Thu Jul 28 01:56:27 2011 UTC ()
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.


(christos)
diff -r1.43 -r1.44 src/lib/libedit/Makefile
diff -r1.65 -r1.66 src/lib/libedit/el.c
diff -r1.23 -r1.24 src/lib/libedit/el.h
diff -r1.23 -r0 src/lib/libedit/key.c
diff -r1.13 -r0 src/lib/libedit/key.h
diff -r0 -r1.1 src/lib/libedit/keymacro.c
diff -r0 -r1.1 src/lib/libedit/keymacro.h
diff -r1.26 -r1.27 src/lib/libedit/map.c
diff -r1.62 -r1.63 src/lib/libedit/read.c
diff -r1.1 -r1.2 src/lib/libedit/terminal.c
diff -r1.1 -r1.2 src/lib/libedit/terminal.h
diff -r1.36 -r1.37 src/lib/libedit/tty.c

cvs diff -r1.43 -r1.44 src/lib/libedit/Makefile (expand / switch to unified diff)

--- src/lib/libedit/Makefile 2011/07/28 01:05:20 1.43
+++ src/lib/libedit/Makefile 2011/07/28 01:56:26 1.44
@@ -1,26 +1,26 @@ @@ -1,26 +1,26 @@
1# $NetBSD: Makefile,v 1.43 2011/07/28 01:05:20 christos Exp $ 1# $NetBSD: Makefile,v 1.44 2011/07/28 01:56:26 christos Exp $
2# @(#)Makefile 8.1 (Berkeley) 6/4/93 2# @(#)Makefile 8.1 (Berkeley) 6/4/93
3 3
4USE_SHLIBDIR= yes 4USE_SHLIBDIR= yes
5 5
6WIDECHAR ?= yes 6WIDECHAR ?= yes
7WARNS= 4 7WARNS= 4
8LIB= edit 8LIB= edit
9 9
10LIBDPLIBS+= terminfo ${.CURDIR}/../libterminfo 10LIBDPLIBS+= terminfo ${.CURDIR}/../libterminfo
11 11
12OSRCS= chared.c common.c el.c emacs.c fcns.c filecomplete.c help.c \ 12OSRCS= chared.c common.c el.c emacs.c fcns.c filecomplete.c help.c \
13 hist.c key.c map.c chartype.c \ 13 hist.c keymacro.c map.c chartype.c \
14 parse.c prompt.c read.c refresh.c search.c sig.c terminal.c tty.c vi.c 14 parse.c prompt.c read.c refresh.c search.c sig.c terminal.c tty.c vi.c
15 15
16MAN= editline.3 editrc.5 16MAN= editline.3 editrc.5
17 17
18MLINKS= editline.3 el_init.3 editline.3 el_end.3 editline.3 el_reset.3 \ 18MLINKS= editline.3 el_init.3 editline.3 el_end.3 editline.3 el_reset.3 \
19 editline.3 el_gets.3 editline.3 el_getc.3 editline.3 el_push.3 \ 19 editline.3 el_gets.3 editline.3 el_getc.3 editline.3 el_push.3 \
20 editline.3 el_parse.3 editline.3 el_set.3 editline.3 el_get.3 \ 20 editline.3 el_parse.3 editline.3 el_set.3 editline.3 el_get.3 \
21 editline.3 el_source.3 editline.3 el_resize.3 editline.3 el_line.3 \ 21 editline.3 el_source.3 editline.3 el_resize.3 editline.3 el_line.3 \
22 editline.3 el_insertstr.3 editline.3 el_deletestr.3 \ 22 editline.3 el_insertstr.3 editline.3 el_deletestr.3 \
23 editline.3 history_init.3 editline.3 history_end.3 \ 23 editline.3 history_init.3 editline.3 history_end.3 \
24 editline.3 history.3 \ 24 editline.3 history.3 \
25 editline.3 tok_init.3 editline.3 tok_end.3 editline.3 tok_reset.3 \ 25 editline.3 tok_init.3 editline.3 tok_end.3 editline.3 tok_reset.3 \
26 editline.3 tok_line.3 editline.3 tok_str.3 26 editline.3 tok_line.3 editline.3 tok_str.3

cvs diff -r1.65 -r1.66 src/lib/libedit/el.c (expand / switch to unified diff)

--- src/lib/libedit/el.c 2011/07/28 01:04:41 1.65
+++ src/lib/libedit/el.c 2011/07/28 01:56:27 1.66
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: el.c,v 1.65 2011/07/28 01:04:41 christos Exp $ */ 1/* $NetBSD: el.c,v 1.66 2011/07/28 01:56:27 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University. 8 * Christos Zoulas of Cornell University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include "config.h" 35#include "config.h"
36#if !defined(lint) && !defined(SCCSID) 36#if !defined(lint) && !defined(SCCSID)
37#if 0 37#if 0
38static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94"; 38static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
39#else 39#else
40__RCSID("$NetBSD: el.c,v 1.65 2011/07/28 01:04:41 christos Exp $"); 40__RCSID("$NetBSD: el.c,v 1.66 2011/07/28 01:56:27 christos Exp $");
41#endif 41#endif
42#endif /* not lint && not SCCSID */ 42#endif /* not lint && not SCCSID */
43 43
44/* 44/*
45 * el.c: EditLine interface functions 45 * el.c: EditLine interface functions
46 */ 46 */
47#include <sys/types.h> 47#include <sys/types.h>
48#include <sys/param.h> 48#include <sys/param.h>
49#include <string.h> 49#include <string.h>
50#include <stdlib.h> 50#include <stdlib.h>
51#include <stdarg.h> 51#include <stdarg.h>
52#include <ctype.h> 52#include <ctype.h>
53#include <locale.h> 53#include <locale.h>
@@ -87,27 +87,27 @@ el_init(const char *prog, FILE *fin, FIL @@ -87,27 +87,27 @@ el_init(const char *prog, FILE *fin, FIL
87 el->el_flags = 0; 87 el->el_flags = 0;
88#ifdef WIDECHAR 88#ifdef WIDECHAR
89 if (setlocale(LC_CTYPE, NULL) != NULL){ 89 if (setlocale(LC_CTYPE, NULL) != NULL){
90 if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0) 90 if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
91 el->el_flags |= CHARSET_IS_UTF8; 91 el->el_flags |= CHARSET_IS_UTF8;
92 } 92 }
93#endif 93#endif
94 94
95 if (terminal_init(el) == -1) { 95 if (terminal_init(el) == -1) {
96 el_free(el->el_prog); 96 el_free(el->el_prog);
97 el_free(el); 97 el_free(el);
98 return NULL; 98 return NULL;
99 } 99 }
100 (void) key_init(el); 100 (void) keymacro_init(el);
101 (void) map_init(el); 101 (void) map_init(el);
102 if (tty_init(el) == -1) 102 if (tty_init(el) == -1)
103 el->el_flags |= NO_TTY; 103 el->el_flags |= NO_TTY;
104 (void) ch_init(el); 104 (void) ch_init(el);
105 (void) search_init(el); 105 (void) search_init(el);
106 (void) hist_init(el); 106 (void) hist_init(el);
107 (void) prompt_init(el); 107 (void) prompt_init(el);
108 (void) sig_init(el); 108 (void) sig_init(el);
109 (void) read_init(el); 109 (void) read_init(el);
110 110
111 return (el); 111 return (el);
112} 112}
113 113
@@ -115,27 +115,27 @@ el_init(const char *prog, FILE *fin, FIL @@ -115,27 +115,27 @@ el_init(const char *prog, FILE *fin, FIL
115/* el_end(): 115/* el_end():
116 * Clean up. 116 * Clean up.
117 */ 117 */
118public void 118public void
119el_end(EditLine *el) 119el_end(EditLine *el)
120{ 120{
121 121
122 if (el == NULL) 122 if (el == NULL)
123 return; 123 return;
124 124
125 el_reset(el); 125 el_reset(el);
126 126
127 terminal_end(el); 127 terminal_end(el);
128 key_end(el); 128 keymacro_end(el);
129 map_end(el); 129 map_end(el);
130 tty_end(el); 130 tty_end(el);
131 ch_end(el); 131 ch_end(el);
132 search_end(el); 132 search_end(el);
133 hist_end(el); 133 hist_end(el);
134 prompt_end(el); 134 prompt_end(el);
135 sig_end(el); 135 sig_end(el);
136 136
137 el_free((ptr_t) el->el_prog); 137 el_free((ptr_t) el->el_prog);
138#ifdef WIDECHAR 138#ifdef WIDECHAR
139 el_free((ptr_t) el->el_scratch.cbuff); 139 el_free((ptr_t) el->el_scratch.cbuff);
140 el_free((ptr_t) el->el_scratch.wbuff); 140 el_free((ptr_t) el->el_scratch.wbuff);
141 el_free((ptr_t) el->el_lgcyconv.cbuff); 141 el_free((ptr_t) el->el_lgcyconv.cbuff);

cvs diff -r1.23 -r1.24 src/lib/libedit/el.h (expand / switch to unified diff)

--- src/lib/libedit/el.h 2011/07/28 01:05:20 1.23
+++ src/lib/libedit/el.h 2011/07/28 01:56:27 1.24
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: el.h,v 1.23 2011/07/28 01:05:20 christos Exp $ */ 1/* $NetBSD: el.h,v 1.24 2011/07/28 01:56:27 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University. 8 * Christos Zoulas of Cornell University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -90,27 +90,27 @@ typedef struct el_state_t { @@ -90,27 +90,27 @@ typedef struct el_state_t {
90 el_action_t thiscmd; /* this command */ 90 el_action_t thiscmd; /* this command */
91 Char thisch; /* char that generated it */ 91 Char thisch; /* char that generated it */
92} el_state_t; 92} el_state_t;
93 93
94/* 94/*
95 * Until we come up with something better... 95 * Until we come up with something better...
96 */ 96 */
97#define el_malloc(a) malloc(a) 97#define el_malloc(a) malloc(a)
98#define el_realloc(a,b) realloc(a, b) 98#define el_realloc(a,b) realloc(a, b)
99#define el_free(a) free(a) 99#define el_free(a) free(a)
100 100
101#include "tty.h" 101#include "tty.h"
102#include "prompt.h" 102#include "prompt.h"
103#include "key.h" 103#include "keymacro.h"
104#include "terminal.h" 104#include "terminal.h"
105#include "refresh.h" 105#include "refresh.h"
106#include "chared.h" 106#include "chared.h"
107#include "common.h" 107#include "common.h"
108#include "search.h" 108#include "search.h"
109#include "hist.h" 109#include "hist.h"
110#include "map.h" 110#include "map.h"
111#include "parse.h" 111#include "parse.h"
112#include "sig.h" 112#include "sig.h"
113#include "help.h" 113#include "help.h"
114#include "read.h" 114#include "read.h"
115 115
116struct editline { 116struct editline {
@@ -126,27 +126,27 @@ struct editline { @@ -126,27 +126,27 @@ struct editline {
126 coord_t el_cursor; /* Cursor location */ 126 coord_t el_cursor; /* Cursor location */
127 Char **el_display; /* Real screen image = what is there */ 127 Char **el_display; /* Real screen image = what is there */
128 Char **el_vdisplay; /* Virtual screen image = what we see */ 128 Char **el_vdisplay; /* Virtual screen image = what we see */
129 void *el_data; /* Client data */ 129 void *el_data; /* Client data */
130 el_line_t el_line; /* The current line information */ 130 el_line_t el_line; /* The current line information */
131 el_state_t el_state; /* Current editor state */ 131 el_state_t el_state; /* Current editor state */
132 el_terminal_t el_terminal; /* Terminal dependent stuff */ 132 el_terminal_t el_terminal; /* Terminal dependent stuff */
133 el_tty_t el_tty; /* Tty dependent stuff */ 133 el_tty_t el_tty; /* Tty dependent stuff */
134 el_refresh_t el_refresh; /* Refresh stuff */ 134 el_refresh_t el_refresh; /* Refresh stuff */
135 el_prompt_t el_prompt; /* Prompt stuff */ 135 el_prompt_t el_prompt; /* Prompt stuff */
136 el_prompt_t el_rprompt; /* Prompt stuff */ 136 el_prompt_t el_rprompt; /* Prompt stuff */
137 el_chared_t el_chared; /* Characted editor stuff */ 137 el_chared_t el_chared; /* Characted editor stuff */
138 el_map_t el_map; /* Key mapping stuff */ 138 el_map_t el_map; /* Key mapping stuff */
139 el_key_t el_key; /* Key binding stuff */ 139 el_keymacro_t el_keymacro; /* Key binding stuff */
140 el_history_t el_history; /* History stuff */ 140 el_history_t el_history; /* History stuff */
141 el_search_t el_search; /* Search stuff */ 141 el_search_t el_search; /* Search stuff */
142 el_signal_t el_signal; /* Signal handling stuff */ 142 el_signal_t el_signal; /* Signal handling stuff */
143 el_read_t el_read; /* Character reading stuff */ 143 el_read_t el_read; /* Character reading stuff */
144#ifdef WIDECHAR 144#ifdef WIDECHAR
145 ct_buffer_t el_scratch; /* Scratch conversion buffer */ 145 ct_buffer_t el_scratch; /* Scratch conversion buffer */
146 ct_buffer_t el_lgcyconv; /* Buffer for legacy wrappers */ 146 ct_buffer_t el_lgcyconv; /* Buffer for legacy wrappers */
147 LineInfo el_lgcylinfo; /* Legacy LineInfo buffer */ 147 LineInfo el_lgcylinfo; /* Legacy LineInfo buffer */
148#endif 148#endif
149}; 149};
150 150
151protected int el_editmode(EditLine *, int, const Char **); 151protected int el_editmode(EditLine *, int, const Char **);
152 152

File Deleted: src/lib/libedit/Attic/key.c

File Deleted: src/lib/libedit/Attic/key.h

File Added: src/lib/libedit/keymacro.c
/*	$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);
}


File Added: src/lib/libedit/keymacro.h
/*	$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 */

cvs diff -r1.26 -r1.27 src/lib/libedit/map.c (expand / switch to unified diff)

--- src/lib/libedit/map.c 2011/07/28 01:05:20 1.26
+++ src/lib/libedit/map.c 2011/07/28 01:56:27 1.27
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: map.c,v 1.26 2011/07/28 01:05:20 christos Exp $ */ 1/* $NetBSD: map.c,v 1.27 2011/07/28 01:56:27 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University. 8 * Christos Zoulas of Cornell University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include "config.h" 35#include "config.h"
36#if !defined(lint) && !defined(SCCSID) 36#if !defined(lint) && !defined(SCCSID)
37#if 0 37#if 0
38static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93"; 38static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
39#else 39#else
40__RCSID("$NetBSD: map.c,v 1.26 2011/07/28 01:05:20 christos Exp $"); 40__RCSID("$NetBSD: map.c,v 1.27 2011/07/28 01:56:27 christos Exp $");
41#endif 41#endif
42#endif /* not lint && not SCCSID */ 42#endif /* not lint && not SCCSID */
43 43
44/* 44/*
45 * map.c: Editor function definitions 45 * map.c: Editor function definitions
46 */ 46 */
47#include <stdlib.h> 47#include <stdlib.h>
48#include "el.h" 48#include "el.h"
49 49
50private void map_print_key(EditLine *, el_action_t *, const Char *); 50private void map_print_key(EditLine *, el_action_t *, const Char *);
51private void map_print_some_keys(EditLine *, el_action_t *, Int, Int); 51private void map_print_some_keys(EditLine *, el_action_t *, Int, Int);
52private void map_print_all_keys(EditLine *); 52private void map_print_all_keys(EditLine *);
53private void map_init_nls(EditLine *); 53private void map_init_nls(EditLine *);
@@ -995,49 +995,49 @@ map_init_meta(EditLine *el) @@ -995,49 +995,49 @@ map_init_meta(EditLine *el)
995 } else 995 } else
996 map = alt; 996 map = alt;
997 } 997 }
998 buf[0] = (Char) i; 998 buf[0] = (Char) i;
999 buf[2] = 0; 999 buf[2] = 0;
1000 for (i = 0200; i <= 0377; i++) 1000 for (i = 0200; i <= 0377; i++)
1001 switch (map[i]) { 1001 switch (map[i]) {
1002 case ED_INSERT: 1002 case ED_INSERT:
1003 case ED_UNASSIGNED: 1003 case ED_UNASSIGNED:
1004 case ED_SEQUENCE_LEAD_IN: 1004 case ED_SEQUENCE_LEAD_IN:
1005 break; 1005 break;
1006 default: 1006 default:
1007 buf[1] = i & 0177; 1007 buf[1] = i & 0177;
1008 key_add(el, buf, key_map_cmd(el, (int) map[i]), XK_CMD); 1008 keymacro_add(el, buf, keymacro_map_cmd(el, (int) map[i]), XK_CMD);
1009 break; 1009 break;
1010 } 1010 }
1011 map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN; 1011 map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
1012} 1012}
1013 1013
1014 1014
1015/* map_init_vi(): 1015/* map_init_vi():
1016 * Initialize the vi bindings 1016 * Initialize the vi bindings
1017 */ 1017 */
1018protected void 1018protected void
1019map_init_vi(EditLine *el) 1019map_init_vi(EditLine *el)
1020{ 1020{
1021 int i; 1021 int i;
1022 el_action_t *key = el->el_map.key; 1022 el_action_t *key = el->el_map.key;
1023 el_action_t *alt = el->el_map.alt; 1023 el_action_t *alt = el->el_map.alt;
1024 const el_action_t *vii = el->el_map.vii; 1024 const el_action_t *vii = el->el_map.vii;
1025 const el_action_t *vic = el->el_map.vic; 1025 const el_action_t *vic = el->el_map.vic;
1026 1026
1027 el->el_map.type = MAP_VI; 1027 el->el_map.type = MAP_VI;
1028 el->el_map.current = el->el_map.key; 1028 el->el_map.current = el->el_map.key;
1029 1029
1030 key_reset(el); 1030 keymacro_reset(el);
1031 1031
1032 for (i = 0; i < N_KEYS; i++) { 1032 for (i = 0; i < N_KEYS; i++) {
1033 key[i] = vii[i]; 1033 key[i] = vii[i];
1034 alt[i] = vic[i]; 1034 alt[i] = vic[i];
1035 } 1035 }
1036 1036
1037 map_init_meta(el); 1037 map_init_meta(el);
1038 map_init_nls(el); 1038 map_init_nls(el);
1039 1039
1040 tty_bind_char(el, 1); 1040 tty_bind_char(el, 1);
1041 terminal_bind_arrow(el); 1041 terminal_bind_arrow(el);
1042} 1042}
1043 1043
@@ -1046,40 +1046,40 @@ map_init_vi(EditLine *el) @@ -1046,40 +1046,40 @@ map_init_vi(EditLine *el)
1046 * Initialize the emacs bindings 1046 * Initialize the emacs bindings
1047 */ 1047 */
1048protected void 1048protected void
1049map_init_emacs(EditLine *el) 1049map_init_emacs(EditLine *el)
1050{ 1050{
1051 int i; 1051 int i;
1052 Char buf[3]; 1052 Char buf[3];
1053 el_action_t *key = el->el_map.key; 1053 el_action_t *key = el->el_map.key;
1054 el_action_t *alt = el->el_map.alt; 1054 el_action_t *alt = el->el_map.alt;
1055 const el_action_t *emacs = el->el_map.emacs; 1055 const el_action_t *emacs = el->el_map.emacs;
1056 1056
1057 el->el_map.type = MAP_EMACS; 1057 el->el_map.type = MAP_EMACS;
1058 el->el_map.current = el->el_map.key; 1058 el->el_map.current = el->el_map.key;
1059 key_reset(el); 1059 keymacro_reset(el);
1060 1060
1061 for (i = 0; i < N_KEYS; i++) { 1061 for (i = 0; i < N_KEYS; i++) {
1062 key[i] = emacs[i]; 1062 key[i] = emacs[i];
1063 alt[i] = ED_UNASSIGNED; 1063 alt[i] = ED_UNASSIGNED;
1064 } 1064 }
1065 1065
1066 map_init_meta(el); 1066 map_init_meta(el);
1067 map_init_nls(el); 1067 map_init_nls(el);
1068 1068
1069 buf[0] = CONTROL('X'); 1069 buf[0] = CONTROL('X');
1070 buf[1] = CONTROL('X'); 1070 buf[1] = CONTROL('X');
1071 buf[2] = 0; 1071 buf[2] = 0;
1072 key_add(el, buf, key_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD); 1072 keymacro_add(el, buf, keymacro_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
1073 1073
1074 tty_bind_char(el, 1); 1074 tty_bind_char(el, 1);
1075 terminal_bind_arrow(el); 1075 terminal_bind_arrow(el);
1076} 1076}
1077 1077
1078 1078
1079/* map_set_editor(): 1079/* map_set_editor():
1080 * Set the editor 1080 * Set the editor
1081 */ 1081 */
1082protected int 1082protected int
1083map_set_editor(EditLine *el, Char *editor) 1083map_set_editor(EditLine *el, Char *editor)
1084{ 1084{
1085 1085
@@ -1116,92 +1116,92 @@ map_get_editor(EditLine *el, const Char  @@ -1116,92 +1116,92 @@ map_get_editor(EditLine *el, const Char
1116} 1116}
1117 1117
1118 1118
1119/* map_print_key(): 1119/* map_print_key():
1120 * Print the function description for 1 key 1120 * Print the function description for 1 key
1121 */ 1121 */
1122private void 1122private void
1123map_print_key(EditLine *el, el_action_t *map, const Char *in) 1123map_print_key(EditLine *el, el_action_t *map, const Char *in)
1124{ 1124{
1125 char outbuf[EL_BUFSIZ]; 1125 char outbuf[EL_BUFSIZ];
1126 el_bindings_t *bp, *ep; 1126 el_bindings_t *bp, *ep;
1127 1127
1128 if (in[0] == '\0' || in[1] == '\0') { 1128 if (in[0] == '\0' || in[1] == '\0') {
1129 (void) key__decode_str(in, outbuf, sizeof(outbuf), ""); 1129 (void) keymacro__decode_str(in, outbuf, sizeof(outbuf), "");
1130 ep = &el->el_map.help[el->el_map.nfunc]; 1130 ep = &el->el_map.help[el->el_map.nfunc];
1131 for (bp = el->el_map.help; bp < ep; bp++) 1131 for (bp = el->el_map.help; bp < ep; bp++)
1132 if (bp->func == map[(unsigned char) *in]) { 1132 if (bp->func == map[(unsigned char) *in]) {
1133 (void) fprintf(el->el_outfile, 1133 (void) fprintf(el->el_outfile,
1134 "%s\t->\t" FSTR "\n", outbuf, bp->name); 1134 "%s\t->\t" FSTR "\n", outbuf, bp->name);
1135 return; 1135 return;
1136 } 1136 }
1137 } else 1137 } else
1138 key_print(el, in); 1138 keymacro_print(el, in);
1139} 1139}
1140 1140
1141 1141
1142/* map_print_some_keys(): 1142/* map_print_some_keys():
1143 * Print keys from first to last 1143 * Print keys from first to last
1144 */ 1144 */
1145private void 1145private void
1146map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last) 1146map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last)
1147{ 1147{
1148 el_bindings_t *bp, *ep; 1148 el_bindings_t *bp, *ep;
1149 Char firstbuf[2], lastbuf[2]; 1149 Char firstbuf[2], lastbuf[2];
1150 char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ]; 1150 char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ];
1151 1151
1152 firstbuf[0] = first; 1152 firstbuf[0] = first;
1153 firstbuf[1] = 0; 1153 firstbuf[1] = 0;
1154 lastbuf[0] = last; 1154 lastbuf[0] = last;
1155 lastbuf[1] = 0; 1155 lastbuf[1] = 0;
1156 if (map[first] == ED_UNASSIGNED) { 1156 if (map[first] == ED_UNASSIGNED) {
1157 if (first == last) { 1157 if (first == last) {
1158 (void) key__decode_str(firstbuf, unparsbuf,  1158 (void) keymacro__decode_str(firstbuf, unparsbuf,
1159 sizeof(unparsbuf), STRQQ); 1159 sizeof(unparsbuf), STRQQ);
1160 (void) fprintf(el->el_outfile, 1160 (void) fprintf(el->el_outfile,
1161 "%-15s-> is undefined\n", unparsbuf); 1161 "%-15s-> is undefined\n", unparsbuf);
1162 } 1162 }
1163 return; 1163 return;
1164 } 1164 }
1165 ep = &el->el_map.help[el->el_map.nfunc]; 1165 ep = &el->el_map.help[el->el_map.nfunc];
1166 for (bp = el->el_map.help; bp < ep; bp++) { 1166 for (bp = el->el_map.help; bp < ep; bp++) {
1167 if (bp->func == map[first]) { 1167 if (bp->func == map[first]) {
1168 if (first == last) { 1168 if (first == last) {
1169 (void) key__decode_str(firstbuf, unparsbuf,  1169 (void) keymacro__decode_str(firstbuf, unparsbuf,
1170 sizeof(unparsbuf), STRQQ); 1170 sizeof(unparsbuf), STRQQ);
1171 (void) fprintf(el->el_outfile, "%-15s-> " FSTR "\n", 1171 (void) fprintf(el->el_outfile, "%-15s-> " FSTR "\n",
1172 unparsbuf, bp->name); 1172 unparsbuf, bp->name);
1173 } else { 1173 } else {
1174 (void) key__decode_str(firstbuf, unparsbuf,  1174 (void) keymacro__decode_str(firstbuf, unparsbuf,
1175 sizeof(unparsbuf), STRQQ); 1175 sizeof(unparsbuf), STRQQ);
1176 (void) key__decode_str(lastbuf, extrabuf,  1176 (void) keymacro__decode_str(lastbuf, extrabuf,
1177 sizeof(extrabuf), STRQQ); 1177 sizeof(extrabuf), STRQQ);
1178 (void) fprintf(el->el_outfile, 1178 (void) fprintf(el->el_outfile,
1179 "%-4s to %-7s-> " FSTR "\n", 1179 "%-4s to %-7s-> " FSTR "\n",
1180 unparsbuf, extrabuf, bp->name); 1180 unparsbuf, extrabuf, bp->name);
1181 } 1181 }
1182 return; 1182 return;
1183 } 1183 }
1184 } 1184 }
1185#ifdef MAP_DEBUG 1185#ifdef MAP_DEBUG
1186 if (map == el->el_map.key) { 1186 if (map == el->el_map.key) {
1187 (void) key__decode_str(firstbuf, unparsbuf,  1187 (void) keymacro__decode_str(firstbuf, unparsbuf,
1188 sizeof(unparsbuf), STRQQ); 1188 sizeof(unparsbuf), STRQQ);
1189 (void) fprintf(el->el_outfile, 1189 (void) fprintf(el->el_outfile,
1190 "BUG!!! %s isn't bound to anything.\n", unparsbuf); 1190 "BUG!!! %s isn't bound to anything.\n", unparsbuf);
1191 (void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n", 1191 (void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
1192 first, el->el_map.key[first]); 1192 first, el->el_map.key[first]);
1193 } else { 1193 } else {
1194 (void) key__decode_str(firstbuf, unparsbuf,  1194 (void) keymacro__decode_str(firstbuf, unparsbuf,
1195 sizeof(unparsbuf), STRQQ); 1195 sizeof(unparsbuf), STRQQ);
1196 (void) fprintf(el->el_outfile, 1196 (void) fprintf(el->el_outfile,
1197 "BUG!!! %s isn't bound to anything.\n", unparsbuf); 1197 "BUG!!! %s isn't bound to anything.\n", unparsbuf);
1198 (void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n", 1198 (void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n",
1199 first, el->el_map.alt[first]); 1199 first, el->el_map.alt[first]);
1200 } 1200 }
1201#endif 1201#endif
1202 EL_ABORT((el->el_errfile, "Error printing keys\n")); 1202 EL_ABORT((el->el_errfile, "Error printing keys\n"));
1203} 1203}
1204 1204
1205 1205
1206/* map_print_all_keys(): 1206/* map_print_all_keys():
1207 * Print the function description for all keys. 1207 * Print the function description for all keys.
@@ -1222,27 +1222,27 @@ map_print_all_keys(EditLine *el) @@ -1222,27 +1222,27 @@ map_print_all_keys(EditLine *el)
1222 map_print_some_keys(el, el->el_map.key, prev, i - 1); 1222 map_print_some_keys(el, el->el_map.key, prev, i - 1);
1223 1223
1224 (void) fprintf(el->el_outfile, "Alternative key bindings\n"); 1224 (void) fprintf(el->el_outfile, "Alternative key bindings\n");
1225 prev = 0; 1225 prev = 0;
1226 for (i = 0; i < N_KEYS; i++) { 1226 for (i = 0; i < N_KEYS; i++) {
1227 if (el->el_map.alt[prev] == el->el_map.alt[i]) 1227 if (el->el_map.alt[prev] == el->el_map.alt[i])
1228 continue; 1228 continue;
1229 map_print_some_keys(el, el->el_map.alt, prev, i - 1); 1229 map_print_some_keys(el, el->el_map.alt, prev, i - 1);
1230 prev = i; 1230 prev = i;
1231 } 1231 }
1232 map_print_some_keys(el, el->el_map.alt, prev, i - 1); 1232 map_print_some_keys(el, el->el_map.alt, prev, i - 1);
1233 1233
1234 (void) fprintf(el->el_outfile, "Multi-character bindings\n"); 1234 (void) fprintf(el->el_outfile, "Multi-character bindings\n");
1235 key_print(el, STR("")); 1235 keymacro_print(el, STR(""));
1236 (void) fprintf(el->el_outfile, "Arrow key bindings\n"); 1236 (void) fprintf(el->el_outfile, "Arrow key bindings\n");
1237 terminal_print_arrow(el, STR("")); 1237 terminal_print_arrow(el, STR(""));
1238} 1238}
1239 1239
1240 1240
1241/* map_bind(): 1241/* map_bind():
1242 * Add/remove/change bindings 1242 * Add/remove/change bindings
1243 */ 1243 */
1244protected int 1244protected int
1245map_bind(EditLine *el, int argc, const Char **argv) 1245map_bind(EditLine *el, int argc, const Char **argv)
1246{ 1246{
1247 el_action_t *map; 1247 el_action_t *map;
1248 int ntype, rem; 1248 int ntype, rem;
@@ -1315,77 +1315,77 @@ map_bind(EditLine *el, int argc, const C @@ -1315,77 +1315,77 @@ map_bind(EditLine *el, int argc, const C
1315 in = argv[argc++]; 1315 in = argv[argc++];
1316 else if ((in = parse__string(inbuf, argv[argc++])) == NULL) { 1316 else if ((in = parse__string(inbuf, argv[argc++])) == NULL) {
1317 (void) fprintf(el->el_errfile, 1317 (void) fprintf(el->el_errfile,
1318 "" FSTR ": Invalid \\ or ^ in instring.\n", 1318 "" FSTR ": Invalid \\ or ^ in instring.\n",
1319 argv[0]); 1319 argv[0]);
1320 return (-1); 1320 return (-1);
1321 } 1321 }
1322 if (rem) { 1322 if (rem) {
1323 if (key) { 1323 if (key) {
1324 (void) terminal_clear_arrow(el, in); 1324 (void) terminal_clear_arrow(el, in);
1325 return (-1); 1325 return (-1);
1326 } 1326 }
1327 if (in[1]) 1327 if (in[1])
1328 (void) key_delete(el, in); 1328 (void) keymacro_delete(el, in);
1329 else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN) 1329 else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
1330 (void) key_delete(el, in); 1330 (void) keymacro_delete(el, in);
1331 else 1331 else
1332 map[(unsigned char) *in] = ED_UNASSIGNED; 1332 map[(unsigned char) *in] = ED_UNASSIGNED;
1333 return (0); 1333 return (0);
1334 } 1334 }
1335 if (argv[argc] == NULL) { 1335 if (argv[argc] == NULL) {
1336 if (key) 1336 if (key)
1337 terminal_print_arrow(el, in); 1337 terminal_print_arrow(el, in);
1338 else 1338 else
1339 map_print_key(el, map, in); 1339 map_print_key(el, map, in);
1340 return (0); 1340 return (0);
1341 } 1341 }
1342#ifdef notyet 1342#ifdef notyet
1343 if (argv[argc + 1] != NULL) { 1343 if (argv[argc + 1] != NULL) {
1344 bindkey_usage(); 1344 bindkeymacro_usage();
1345 return (-1); 1345 return (-1);
1346 } 1346 }
1347#endif 1347#endif
1348 1348
1349 switch (ntype) { 1349 switch (ntype) {
1350 case XK_STR: 1350 case XK_STR:
1351 case XK_EXE: 1351 case XK_EXE:
1352 if ((out = parse__string(outbuf, argv[argc])) == NULL) { 1352 if ((out = parse__string(outbuf, argv[argc])) == NULL) {
1353 (void) fprintf(el->el_errfile, 1353 (void) fprintf(el->el_errfile,
1354 "" FSTR ": Invalid \\ or ^ in outstring.\n", argv[0]); 1354 "" FSTR ": Invalid \\ or ^ in outstring.\n", argv[0]);
1355 return (-1); 1355 return (-1);
1356 } 1356 }
1357 if (key) 1357 if (key)
1358 terminal_set_arrow(el, in, key_map_str(el, out), ntype); 1358 terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
1359 else 1359 else
1360 key_add(el, in, key_map_str(el, out), ntype); 1360 keymacro_add(el, in, keymacro_map_str(el, out), ntype);
1361 map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN; 1361 map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
1362 break; 1362 break;
1363 1363
1364 case XK_CMD: 1364 case XK_CMD:
1365 if ((cmd = parse_cmd(el, argv[argc])) == -1) { 1365 if ((cmd = parse_cmd(el, argv[argc])) == -1) {
1366 (void) fprintf(el->el_errfile, 1366 (void) fprintf(el->el_errfile,
1367 "" FSTR ": Invalid command `" FSTR "'.\n", 1367 "" FSTR ": Invalid command `" FSTR "'.\n",
1368 argv[0], argv[argc]); 1368 argv[0], argv[argc]);
1369 return (-1); 1369 return (-1);
1370 } 1370 }
1371 if (key) 1371 if (key)
1372 terminal_set_arrow(el, in, key_map_str(el, out), ntype); 1372 terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
1373 else { 1373 else {
1374 if (in[1]) { 1374 if (in[1]) {
1375 key_add(el, in, key_map_cmd(el, cmd), ntype); 1375 keymacro_add(el, in, keymacro_map_cmd(el, cmd), ntype);
1376 map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN; 1376 map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
1377 } else { 1377 } else {
1378 key_clear(el, map, in); 1378 keymacro_clear(el, map, in);
1379 map[(unsigned char) *in] = cmd; 1379 map[(unsigned char) *in] = cmd;
1380 } 1380 }
1381 } 1381 }
1382 break; 1382 break;
1383 1383
1384 default: 1384 default:
1385 EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype)); 1385 EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
1386 break; 1386 break;
1387 } 1387 }
1388 return (0); 1388 return (0);
1389} 1389}
1390 1390
1391 1391

cvs diff -r1.62 -r1.63 src/lib/libedit/read.c (expand / switch to unified diff)

--- src/lib/libedit/read.c 2011/07/28 00:44:35 1.62
+++ src/lib/libedit/read.c 2011/07/28 01:56:27 1.63
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: read.c,v 1.62 2011/07/28 00:44:35 christos Exp $ */ 1/* $NetBSD: read.c,v 1.63 2011/07/28 01:56:27 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University. 8 * Christos Zoulas of Cornell University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include "config.h" 35#include "config.h"
36#if !defined(lint) && !defined(SCCSID) 36#if !defined(lint) && !defined(SCCSID)
37#if 0 37#if 0
38static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; 38static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
39#else 39#else
40__RCSID("$NetBSD: read.c,v 1.62 2011/07/28 00:44:35 christos Exp $"); 40__RCSID("$NetBSD: read.c,v 1.63 2011/07/28 01:56:27 christos Exp $");
41#endif 41#endif
42#endif /* not lint && not SCCSID */ 42#endif /* not lint && not SCCSID */
43 43
44/* 44/*
45 * read.c: Clean this junk up! This is horrible code. 45 * read.c: Clean this junk up! This is horrible code.
46 * Terminal read functions 46 * Terminal read functions
47 */ 47 */
48#include <errno.h> 48#include <errno.h>
49#include <fcntl.h> 49#include <fcntl.h>
50#include <unistd.h> 50#include <unistd.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <limits.h> 52#include <limits.h>
53#include "el.h" 53#include "el.h"
@@ -258,28 +258,28 @@ read_getcmd(EditLine *el, el_action_t *c @@ -258,28 +258,28 @@ read_getcmd(EditLine *el, el_action_t *c
258#endif /* KANJI */ 258#endif /* KANJI */
259 259
260 if (el->el_state.metanext) { 260 if (el->el_state.metanext) {
261 el->el_state.metanext = 0; 261 el->el_state.metanext = 0;
262 *ch |= 0200; 262 *ch |= 0200;
263 } 263 }
264#ifdef WIDECHAR 264#ifdef WIDECHAR
265 if (*ch >= N_KEYS) 265 if (*ch >= N_KEYS)
266 cmd = ED_INSERT; 266 cmd = ED_INSERT;
267 else 267 else
268#endif 268#endif
269 cmd = el->el_map.current[(unsigned char) *ch]; 269 cmd = el->el_map.current[(unsigned char) *ch];
270 if (cmd == ED_SEQUENCE_LEAD_IN) { 270 if (cmd == ED_SEQUENCE_LEAD_IN) {
271 key_value_t val; 271 keymacro_value_t val;
272 switch (key_get(el, ch, &val)) { 272 switch (keymacro_get(el, ch, &val)) {
273 case XK_CMD: 273 case XK_CMD:
274 cmd = val.cmd; 274 cmd = val.cmd;
275 break; 275 break;
276 case XK_STR: 276 case XK_STR:
277 FUN(el,push)(el, val.str); 277 FUN(el,push)(el, val.str);
278 break; 278 break;
279#ifdef notyet 279#ifdef notyet
280 case XK_EXE: 280 case XK_EXE:
281 /* XXX: In the future to run a user function */ 281 /* XXX: In the future to run a user function */
282 RunCommand(val.str); 282 RunCommand(val.str);
283 break; 283 break;
284#endif 284#endif
285 default: 285 default:

cvs diff -r1.1 -r1.2 src/lib/libedit/terminal.c (expand / switch to unified diff)

--- src/lib/libedit/terminal.c 2011/07/28 01:05:20 1.1
+++ src/lib/libedit/terminal.c 2011/07/28 01:56:27 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: terminal.c,v 1.1 2011/07/28 01:05:20 christos Exp $ */ 1/* $NetBSD: terminal.c,v 1.2 2011/07/28 01:56:27 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University. 8 * Christos Zoulas of Cornell University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include "config.h" 35#include "config.h"
36#if !defined(lint) && !defined(SCCSID) 36#if !defined(lint) && !defined(SCCSID)
37#if 0 37#if 0
38static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95"; 38static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
39#else 39#else
40__RCSID("$NetBSD: terminal.c,v 1.1 2011/07/28 01:05:20 christos Exp $"); 40__RCSID("$NetBSD: terminal.c,v 1.2 2011/07/28 01:56:27 christos Exp $");
41#endif 41#endif
42#endif /* not lint && not SCCSID */ 42#endif /* not lint && not SCCSID */
43 43
44/* 44/*
45 * term.c: Editor/termcap-curses interface 45 * term.c: Editor/termcap-curses interface
46 * We have to declare a static variable here, since the 46 * We have to declare a static variable here, since the
47 * termcap putchar routine does not take an argument! 47 * termcap putchar routine does not take an argument!
48 */ 48 */
49#include <stdio.h> 49#include <stdio.h>
50#include <signal.h> 50#include <signal.h>
51#include <string.h> 51#include <string.h>
52#include <stdlib.h> 52#include <stdlib.h>
53#include <unistd.h> 53#include <unistd.h>
@@ -55,29 +55,26 @@ __RCSID("$NetBSD: terminal.c,v 1.1 2011/ @@ -55,29 +55,26 @@ __RCSID("$NetBSD: terminal.c,v 1.1 2011/
55#ifdef HAVE_TERMCAP_H 55#ifdef HAVE_TERMCAP_H
56#include <termcap.h> 56#include <termcap.h>
57#endif 57#endif
58#ifdef HAVE_CURSES_H 58#ifdef HAVE_CURSES_H
59#include <curses.h> 59#include <curses.h>
60#elif HAVE_NCURSES_H 60#elif HAVE_NCURSES_H
61#include <ncurses.h> 61#include <ncurses.h>
62#endif 62#endif
63 63
64/* Solaris's term.h does horrid things. */ 64/* Solaris's term.h does horrid things. */
65#if defined(HAVE_TERM_H) && !defined(__sun) 65#if defined(HAVE_TERM_H) && !defined(__sun)
66#include <term.h> 66#include <term.h>
67#endif 67#endif
68#undef key_end 
69#undef key_clear 
70#undef key_print 
71  68
72#include <sys/types.h> 69#include <sys/types.h>
73#include <sys/ioctl.h> 70#include <sys/ioctl.h>
74 71
75#ifdef _REENTRANT 72#ifdef _REENTRANT
76#include <pthread.h> 73#include <pthread.h>
77#endif 74#endif
78 75
79#include "el.h" 76#include "el.h"
80 77
81/* 78/*
82 * IMPORTANT NOTE: these routines are allowed to look at the current screen 79 * IMPORTANT NOTE: these routines are allowed to look at the current screen
83 * and the current position assuming that it is correct. If this is not 80 * and the current position assuming that it is correct. If this is not
@@ -337,27 +334,27 @@ terminal_setflags(EditLine *el) @@ -337,27 +334,27 @@ terminal_setflags(EditLine *el)
337/* terminal_init(): 334/* terminal_init():
338 * Initialize the terminal stuff 335 * Initialize the terminal stuff
339 */ 336 */
340protected int 337protected int
341terminal_init(EditLine *el) 338terminal_init(EditLine *el)
342{ 339{
343 340
344 el->el_terminal.t_buf = (char *) el_malloc(TC_BUFSIZE); 341 el->el_terminal.t_buf = (char *) el_malloc(TC_BUFSIZE);
345 if (el->el_terminal.t_buf == NULL) 342 if (el->el_terminal.t_buf == NULL)
346 return (-1); 343 return (-1);
347 el->el_terminal.t_cap = (char *) el_malloc(TC_BUFSIZE); 344 el->el_terminal.t_cap = (char *) el_malloc(TC_BUFSIZE);
348 if (el->el_terminal.t_cap == NULL) 345 if (el->el_terminal.t_cap == NULL)
349 return (-1); 346 return (-1);
350 el->el_terminal.t_fkey = (fkey_t *) el_malloc(A_K_NKEYS * sizeof(fkey_t)); 347 el->el_terminal.t_fkey = (funckey_t *) el_malloc(A_K_NKEYS * sizeof(funckey_t));
351 if (el->el_terminal.t_fkey == NULL) 348 if (el->el_terminal.t_fkey == NULL)
352 return (-1); 349 return (-1);
353 el->el_terminal.t_loc = 0; 350 el->el_terminal.t_loc = 0;
354 el->el_terminal.t_str = (char **) el_malloc(T_str * sizeof(char *)); 351 el->el_terminal.t_str = (char **) el_malloc(T_str * sizeof(char *));
355 if (el->el_terminal.t_str == NULL) 352 if (el->el_terminal.t_str == NULL)
356 return (-1); 353 return (-1);
357 (void) memset(el->el_terminal.t_str, 0, T_str * sizeof(char *)); 354 (void) memset(el->el_terminal.t_str, 0, T_str * sizeof(char *));
358 el->el_terminal.t_val = (int *) el_malloc(T_val * sizeof(int)); 355 el->el_terminal.t_val = (int *) el_malloc(T_val * sizeof(int));
359 if (el->el_terminal.t_val == NULL) 356 if (el->el_terminal.t_val == NULL)
360 return (-1); 357 return (-1);
361 (void) memset(el->el_terminal.t_val, 0, T_val * sizeof(int)); 358 (void) memset(el->el_terminal.t_val, 0, T_val * sizeof(int));
362 (void) terminal_set(el, NULL); 359 (void) terminal_set(el, NULL);
363 terminal_init_arrow(el); 360 terminal_init_arrow(el);
@@ -1064,27 +1061,27 @@ terminal_change_size(EditLine *el, int l @@ -1064,27 +1061,27 @@ terminal_change_size(EditLine *el, int l
1064 if (terminal_rebuffer_display(el) == -1) 1061 if (terminal_rebuffer_display(el) == -1)
1065 return (-1); 1062 return (-1);
1066 re_clear_display(el); 1063 re_clear_display(el);
1067 return (0); 1064 return (0);
1068} 1065}
1069 1066
1070 1067
1071/* terminal_init_arrow(): 1068/* terminal_init_arrow():
1072 * Initialize the arrow key bindings from termcap 1069 * Initialize the arrow key bindings from termcap
1073 */ 1070 */
1074private void 1071private void
1075terminal_init_arrow(EditLine *el) 1072terminal_init_arrow(EditLine *el)
1076{ 1073{
1077 fkey_t *arrow = el->el_terminal.t_fkey; 1074 funckey_t *arrow = el->el_terminal.t_fkey;
1078 1075
1079 arrow[A_K_DN].name = STR("down"); 1076 arrow[A_K_DN].name = STR("down");
1080 arrow[A_K_DN].key = T_kd; 1077 arrow[A_K_DN].key = T_kd;
1081 arrow[A_K_DN].fun.cmd = ED_NEXT_HISTORY; 1078 arrow[A_K_DN].fun.cmd = ED_NEXT_HISTORY;
1082 arrow[A_K_DN].type = XK_CMD; 1079 arrow[A_K_DN].type = XK_CMD;
1083 1080
1084 arrow[A_K_UP].name = STR("up"); 1081 arrow[A_K_UP].name = STR("up");
1085 arrow[A_K_UP].key = T_ku; 1082 arrow[A_K_UP].key = T_ku;
1086 arrow[A_K_UP].fun.cmd = ED_PREV_HISTORY; 1083 arrow[A_K_UP].fun.cmd = ED_PREV_HISTORY;
1087 arrow[A_K_UP].type = XK_CMD; 1084 arrow[A_K_UP].type = XK_CMD;
1088 1085
1089 arrow[A_K_LT].name = STR("left"); 1086 arrow[A_K_LT].name = STR("left");
1090 arrow[A_K_LT].key = T_kl; 1087 arrow[A_K_LT].key = T_kl;
@@ -1104,135 +1101,135 @@ terminal_init_arrow(EditLine *el) @@ -1104,135 +1101,135 @@ terminal_init_arrow(EditLine *el)
1104 arrow[A_K_EN].name = STR("end"); 1101 arrow[A_K_EN].name = STR("end");
1105 arrow[A_K_EN].key = T_at7; 1102 arrow[A_K_EN].key = T_at7;
1106 arrow[A_K_EN].fun.cmd = ED_MOVE_TO_END; 1103 arrow[A_K_EN].fun.cmd = ED_MOVE_TO_END;
1107 arrow[A_K_EN].type = XK_CMD; 1104 arrow[A_K_EN].type = XK_CMD;
1108} 1105}
1109 1106
1110 1107
1111/* terminal_reset_arrow(): 1108/* terminal_reset_arrow():
1112 * Reset arrow key bindings 1109 * Reset arrow key bindings
1113 */ 1110 */
1114private void 1111private void
1115terminal_reset_arrow(EditLine *el) 1112terminal_reset_arrow(EditLine *el)
1116{ 1113{
1117 fkey_t *arrow = el->el_terminal.t_fkey; 1114 funckey_t *arrow = el->el_terminal.t_fkey;
1118 static const Char strA[] = {033, '[', 'A', '\0'}; 1115 static const Char strA[] = {033, '[', 'A', '\0'};
1119 static const Char strB[] = {033, '[', 'B', '\0'}; 1116 static const Char strB[] = {033, '[', 'B', '\0'};
1120 static const Char strC[] = {033, '[', 'C', '\0'}; 1117 static const Char strC[] = {033, '[', 'C', '\0'};
1121 static const Char strD[] = {033, '[', 'D', '\0'}; 1118 static const Char strD[] = {033, '[', 'D', '\0'};
1122 static const Char strH[] = {033, '[', 'H', '\0'}; 1119 static const Char strH[] = {033, '[', 'H', '\0'};
1123 static const Char strF[] = {033, '[', 'F', '\0'}; 1120 static const Char strF[] = {033, '[', 'F', '\0'};
1124 static const Char stOA[] = {033, 'O', 'A', '\0'}; 1121 static const Char stOA[] = {033, 'O', 'A', '\0'};
1125 static const Char stOB[] = {033, 'O', 'B', '\0'}; 1122 static const Char stOB[] = {033, 'O', 'B', '\0'};
1126 static const Char stOC[] = {033, 'O', 'C', '\0'}; 1123 static const Char stOC[] = {033, 'O', 'C', '\0'};
1127 static const Char stOD[] = {033, 'O', 'D', '\0'}; 1124 static const Char stOD[] = {033, 'O', 'D', '\0'};
1128 static const Char stOH[] = {033, 'O', 'H', '\0'}; 1125 static const Char stOH[] = {033, 'O', 'H', '\0'};
1129 static const Char stOF[] = {033, 'O', 'F', '\0'}; 1126 static const Char stOF[] = {033, 'O', 'F', '\0'};
1130 1127
1131 key_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); 1128 keymacro_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
1132 key_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); 1129 keymacro_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
1133 key_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); 1130 keymacro_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
1134 key_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); 1131 keymacro_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
1135 key_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type); 1132 keymacro_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
1136 key_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type); 1133 keymacro_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
1137 key_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); 1134 keymacro_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
1138 key_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); 1135 keymacro_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
1139 key_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); 1136 keymacro_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
1140 key_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); 1137 keymacro_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
1141 key_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type); 1138 keymacro_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
1142 key_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type); 1139 keymacro_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
1143 1140
1144 if (el->el_map.type == MAP_VI) { 1141 if (el->el_map.type == MAP_VI) {
1145 key_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); 1142 keymacro_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
1146 key_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); 1143 keymacro_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
1147 key_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); 1144 keymacro_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
1148 key_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); 1145 keymacro_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
1149 key_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type); 1146 keymacro_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
1150 key_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type); 1147 keymacro_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
1151 key_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); 1148 keymacro_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
1152 key_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); 1149 keymacro_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
1153 key_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); 1150 keymacro_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
1154 key_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); 1151 keymacro_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
1155 key_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type); 1152 keymacro_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
1156 key_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type); 1153 keymacro_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
1157 } 1154 }
1158} 1155}
1159 1156
1160 1157
1161/* terminal_set_arrow(): 1158/* terminal_set_arrow():
1162 * Set an arrow key binding 1159 * Set an arrow key binding
1163 */ 1160 */
1164protected int 1161protected int
1165terminal_set_arrow(EditLine *el, const Char *name, key_value_t *fun, int type) 1162terminal_set_arrow(EditLine *el, const Char *name, keymacro_value_t *fun, int type)
1166{ 1163{
1167 fkey_t *arrow = el->el_terminal.t_fkey; 1164 funckey_t *arrow = el->el_terminal.t_fkey;
1168 int i; 1165 int i;
1169 1166
1170 for (i = 0; i < A_K_NKEYS; i++) 1167 for (i = 0; i < A_K_NKEYS; i++)
1171 if (Strcmp(name, arrow[i].name) == 0) { 1168 if (Strcmp(name, arrow[i].name) == 0) {
1172 arrow[i].fun = *fun; 1169 arrow[i].fun = *fun;
1173 arrow[i].type = type; 1170 arrow[i].type = type;
1174 return (0); 1171 return (0);
1175 } 1172 }
1176 return (-1); 1173 return (-1);
1177} 1174}
1178 1175
1179 1176
1180/* terminal_clear_arrow(): 1177/* terminal_clear_arrow():
1181 * Clear an arrow key binding 1178 * Clear an arrow key binding
1182 */ 1179 */
1183protected int 1180protected int
1184terminal_clear_arrow(EditLine *el, const Char *name) 1181terminal_clear_arrow(EditLine *el, const Char *name)
1185{ 1182{
1186 fkey_t *arrow = el->el_terminal.t_fkey; 1183 funckey_t *arrow = el->el_terminal.t_fkey;
1187 int i; 1184 int i;
1188 1185
1189 for (i = 0; i < A_K_NKEYS; i++) 1186 for (i = 0; i < A_K_NKEYS; i++)
1190 if (Strcmp(name, arrow[i].name) == 0) { 1187 if (Strcmp(name, arrow[i].name) == 0) {
1191 arrow[i].type = XK_NOD; 1188 arrow[i].type = XK_NOD;
1192 return (0); 1189 return (0);
1193 } 1190 }
1194 return (-1); 1191 return (-1);
1195} 1192}
1196 1193
1197 1194
1198/* terminal_print_arrow(): 1195/* terminal_print_arrow():
1199 * Print the arrow key bindings 1196 * Print the arrow key bindings
1200 */ 1197 */
1201protected void 1198protected void
1202terminal_print_arrow(EditLine *el, const Char *name) 1199terminal_print_arrow(EditLine *el, const Char *name)
1203{ 1200{
1204 int i; 1201 int i;
1205 fkey_t *arrow = el->el_terminal.t_fkey; 1202 funckey_t *arrow = el->el_terminal.t_fkey;
1206 1203
1207 for (i = 0; i < A_K_NKEYS; i++) 1204 for (i = 0; i < A_K_NKEYS; i++)
1208 if (*name == '\0' || Strcmp(name, arrow[i].name) == 0) 1205 if (*name == '\0' || Strcmp(name, arrow[i].name) == 0)
1209 if (arrow[i].type != XK_NOD) 1206 if (arrow[i].type != XK_NOD)
1210 key_kprint(el, arrow[i].name, &arrow[i].fun, 1207 keymacro_kprint(el, arrow[i].name, &arrow[i].fun,
1211 arrow[i].type); 1208 arrow[i].type);
1212} 1209}
1213 1210
1214 1211
1215/* terminal_bind_arrow(): 1212/* terminal_bind_arrow():
1216 * Bind the arrow keys 1213 * Bind the arrow keys
1217 */ 1214 */
1218protected void 1215protected void
1219terminal_bind_arrow(EditLine *el) 1216terminal_bind_arrow(EditLine *el)
1220{ 1217{
1221 el_action_t *map; 1218 el_action_t *map;
1222 const el_action_t *dmap; 1219 const el_action_t *dmap;
1223 int i, j; 1220 int i, j;
1224 char *p; 1221 char *p;
1225 fkey_t *arrow = el->el_terminal.t_fkey; 1222 funckey_t *arrow = el->el_terminal.t_fkey;
1226 1223
1227 /* Check if the components needed are initialized */ 1224 /* Check if the components needed are initialized */
1228 if (el->el_terminal.t_buf == NULL || el->el_map.key == NULL) 1225 if (el->el_terminal.t_buf == NULL || el->el_map.key == NULL)
1229 return; 1226 return;
1230 1227
1231 map = el->el_map.type == MAP_VI ? el->el_map.alt : el->el_map.key; 1228 map = el->el_map.type == MAP_VI ? el->el_map.alt : el->el_map.key;
1232 dmap = el->el_map.type == MAP_VI ? el->el_map.vic : el->el_map.emacs; 1229 dmap = el->el_map.type == MAP_VI ? el->el_map.vic : el->el_map.emacs;
1233 1230
1234 terminal_reset_arrow(el); 1231 terminal_reset_arrow(el);
1235 1232
1236 for (i = 0; i < A_K_NKEYS; i++) { 1233 for (i = 0; i < A_K_NKEYS; i++) {
1237 Char wt_str[VISUAL_WIDTH_MAX]; 1234 Char wt_str[VISUAL_WIDTH_MAX];
1238 Char *px; 1235 Char *px;
@@ -1248,39 +1245,39 @@ terminal_bind_arrow(EditLine *el) @@ -1248,39 +1245,39 @@ terminal_bind_arrow(EditLine *el)
1248 px = wt_str; 1245 px = wt_str;
1249 j = (unsigned char) *p; 1246 j = (unsigned char) *p;
1250 /* 1247 /*
1251 * Assign the arrow keys only if: 1248 * Assign the arrow keys only if:
1252 * 1249 *
1253 * 1. They are multi-character arrow keys and the user 1250 * 1. They are multi-character arrow keys and the user
1254 * has not re-assigned the leading character, or 1251 * has not re-assigned the leading character, or
1255 * has re-assigned the leading character to be 1252 * has re-assigned the leading character to be
1256 * ED_SEQUENCE_LEAD_IN 1253 * ED_SEQUENCE_LEAD_IN
1257 * 2. They are single arrow keys pointing to an 1254 * 2. They are single arrow keys pointing to an
1258 * unassigned key. 1255 * unassigned key.
1259 */ 1256 */
1260 if (arrow[i].type == XK_NOD) 1257 if (arrow[i].type == XK_NOD)
1261 key_clear(el, map, px); 1258 keymacro_clear(el, map, px);
1262 else { 1259 else {
1263 if (p[1] && (dmap[j] == map[j] || 1260 if (p[1] && (dmap[j] == map[j] ||
1264 map[j] == ED_SEQUENCE_LEAD_IN)) { 1261 map[j] == ED_SEQUENCE_LEAD_IN)) {
1265 key_add(el, px, &arrow[i].fun, 1262 keymacro_add(el, px, &arrow[i].fun,
1266 arrow[i].type); 1263 arrow[i].type);
1267 map[j] = ED_SEQUENCE_LEAD_IN; 1264 map[j] = ED_SEQUENCE_LEAD_IN;
1268 } else if (map[j] == ED_UNASSIGNED) { 1265 } else if (map[j] == ED_UNASSIGNED) {
1269 key_clear(el, map, px); 1266 keymacro_clear(el, map, px);
1270 if (arrow[i].type == XK_CMD) 1267 if (arrow[i].type == XK_CMD)
1271 map[j] = arrow[i].fun.cmd; 1268 map[j] = arrow[i].fun.cmd;
1272 else 1269 else
1273 key_add(el, px, &arrow[i].fun, 1270 keymacro_add(el, px, &arrow[i].fun,
1274 arrow[i].type); 1271 arrow[i].type);
1275 } 1272 }
1276 } 1273 }
1277 } 1274 }
1278} 1275}
1279 1276
1280/* terminal_putc(): 1277/* terminal_putc():
1281 * Add a character 1278 * Add a character
1282 */ 1279 */
1283private int 1280private int
1284terminal_putc(int c) 1281terminal_putc(int c)
1285{ 1282{
1286 if (terminal_outfile == NULL) 1283 if (terminal_outfile == NULL)

cvs diff -r1.1 -r1.2 src/lib/libedit/terminal.h (expand / switch to unified diff)

--- src/lib/libedit/terminal.h 2011/07/28 01:05:20 1.1
+++ src/lib/libedit/terminal.h 2011/07/28 01:56:27 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: terminal.h,v 1.1 2011/07/28 01:05:20 christos Exp $ */ 1/* $NetBSD: terminal.h,v 1.2 2011/07/28 01:56:27 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University. 8 * Christos Zoulas of Cornell University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -35,49 +35,49 @@ @@ -35,49 +35,49 @@
35 */ 35 */
36 36
37/* 37/*
38 * el.term.h: Termcap header 38 * el.term.h: Termcap header
39 */ 39 */
40#ifndef _h_el_terminal 40#ifndef _h_el_terminal
41#define _h_el_terminal 41#define _h_el_terminal
42 42
43#include "histedit.h" 43#include "histedit.h"
44 44
45typedef struct { /* Symbolic function key bindings */ 45typedef struct { /* Symbolic function key bindings */
46 const Char *name; /* name of the key */ 46 const Char *name; /* name of the key */
47 int key; /* Index in termcap table */ 47 int key; /* Index in termcap table */
48 key_value_t fun; /* Function bound to it */ 48 keymacro_value_t fun; /* Function bound to it */
49 int type; /* Type of function */ 49 int type; /* Type of function */
50} fkey_t; 50} funckey_t;
51 51
52typedef struct { 52typedef struct {
53 const char *t_name; /* the terminal name */ 53 const char *t_name; /* the terminal name */
54 coord_t t_size; /* # lines and cols */ 54 coord_t t_size; /* # lines and cols */
55 int t_flags; 55 int t_flags;
56#define TERM_CAN_INSERT 0x001 /* Has insert cap */ 56#define TERM_CAN_INSERT 0x001 /* Has insert cap */
57#define TERM_CAN_DELETE 0x002 /* Has delete cap */ 57#define TERM_CAN_DELETE 0x002 /* Has delete cap */
58#define TERM_CAN_CEOL 0x004 /* Has CEOL cap */ 58#define TERM_CAN_CEOL 0x004 /* Has CEOL cap */
59#define TERM_CAN_TAB 0x008 /* Can use tabs */ 59#define TERM_CAN_TAB 0x008 /* Can use tabs */
60#define TERM_CAN_ME 0x010 /* Can turn all attrs. */ 60#define TERM_CAN_ME 0x010 /* Can turn all attrs. */
61#define TERM_CAN_UP 0x020 /* Can move up */ 61#define TERM_CAN_UP 0x020 /* Can move up */
62#define TERM_HAS_META 0x040 /* Has a meta key */ 62#define TERM_HAS_META 0x040 /* Has a meta key */
63#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */ 63#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */
64#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */ 64#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */
65 char *t_buf; /* Termcap buffer */ 65 char *t_buf; /* Termcap buffer */
66 int t_loc; /* location used */ 66 int t_loc; /* location used */
67 char **t_str; /* termcap strings */ 67 char **t_str; /* termcap strings */
68 int *t_val; /* termcap values */ 68 int *t_val; /* termcap values */
69 char *t_cap; /* Termcap buffer */ 69 char *t_cap; /* Termcap buffer */
70 fkey_t *t_fkey; /* Array of keys */ 70 funckey_t *t_fkey; /* Array of keys */
71} el_terminal_t; 71} el_terminal_t;
72 72
73/* 73/*
74 * fKey indexes 74 * fKey indexes
75 */ 75 */
76#define A_K_DN 0 76#define A_K_DN 0
77#define A_K_UP 1 77#define A_K_UP 1
78#define A_K_LT 2 78#define A_K_LT 2
79#define A_K_RT 3 79#define A_K_RT 3
80#define A_K_HO 4 80#define A_K_HO 4
81#define A_K_EN 5 81#define A_K_EN 5
82#define A_K_NKEYS 6 82#define A_K_NKEYS 6
83 83
@@ -85,27 +85,27 @@ protected void terminal_move_to_line(Edi @@ -85,27 +85,27 @@ protected void terminal_move_to_line(Edi
85protected void terminal_move_to_char(EditLine *, int); 85protected void terminal_move_to_char(EditLine *, int);
86protected void terminal_clear_EOL(EditLine *, int); 86protected void terminal_clear_EOL(EditLine *, int);
87protected void terminal_overwrite(EditLine *, const Char *, size_t); 87protected void terminal_overwrite(EditLine *, const Char *, size_t);
88protected void terminal_insertwrite(EditLine *, Char *, int); 88protected void terminal_insertwrite(EditLine *, Char *, int);
89protected void terminal_deletechars(EditLine *, int); 89protected void terminal_deletechars(EditLine *, int);
90protected void terminal_clear_screen(EditLine *); 90protected void terminal_clear_screen(EditLine *);
91protected void terminal_beep(EditLine *); 91protected void terminal_beep(EditLine *);
92protected int terminal_change_size(EditLine *, int, int); 92protected int terminal_change_size(EditLine *, int, int);
93protected int terminal_get_size(EditLine *, int *, int *); 93protected int terminal_get_size(EditLine *, int *, int *);
94protected int terminal_init(EditLine *); 94protected int terminal_init(EditLine *);
95protected void terminal_bind_arrow(EditLine *); 95protected void terminal_bind_arrow(EditLine *);
96protected void terminal_print_arrow(EditLine *, const Char *); 96protected void terminal_print_arrow(EditLine *, const Char *);
97protected int terminal_clear_arrow(EditLine *, const Char *); 97protected int terminal_clear_arrow(EditLine *, const Char *);
98protected int terminal_set_arrow(EditLine *, const Char *, key_value_t *, int); 98protected int terminal_set_arrow(EditLine *, const Char *, keymacro_value_t *, int);
99protected void terminal_end(EditLine *); 99protected void terminal_end(EditLine *);
100protected void terminal_get(EditLine *, const char **); 100protected void terminal_get(EditLine *, const char **);
101protected int terminal_set(EditLine *, const char *); 101protected int terminal_set(EditLine *, const char *);
102protected int terminal_settc(EditLine *, int, const Char **); 102protected int terminal_settc(EditLine *, int, const Char **);
103protected int terminal_gettc(EditLine *, int, char **); 103protected int terminal_gettc(EditLine *, int, char **);
104protected int terminal_telltc(EditLine *, int, const Char **); 104protected int terminal_telltc(EditLine *, int, const Char **);
105protected int terminal_echotc(EditLine *, int, const Char **); 105protected int terminal_echotc(EditLine *, int, const Char **);
106protected void terminal_writec(EditLine *, Int); 106protected void terminal_writec(EditLine *, Int);
107protected int terminal__putc(EditLine *, Int); 107protected int terminal__putc(EditLine *, Int);
108protected void terminal__flush(EditLine *); 108protected void terminal__flush(EditLine *);
109 109
110/* 110/*
111 * Easy access macros 111 * Easy access macros

cvs diff -r1.36 -r1.37 src/lib/libedit/tty.c (expand / switch to unified diff)

--- src/lib/libedit/tty.c 2011/07/28 00:45:50 1.36
+++ src/lib/libedit/tty.c 2011/07/28 01:56:27 1.37
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tty.c,v 1.36 2011/07/28 00:45:50 christos Exp $ */ 1/* $NetBSD: tty.c,v 1.37 2011/07/28 01:56:27 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University. 8 * Christos Zoulas of Cornell University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include "config.h" 35#include "config.h"
36#if !defined(lint) && !defined(SCCSID) 36#if !defined(lint) && !defined(SCCSID)
37#if 0 37#if 0
38static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93"; 38static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
39#else 39#else
40__RCSID("$NetBSD: tty.c,v 1.36 2011/07/28 00:45:50 christos Exp $"); 40__RCSID("$NetBSD: tty.c,v 1.37 2011/07/28 01:56:27 christos Exp $");
41#endif 41#endif
42#endif /* not lint && not SCCSID */ 42#endif /* not lint && not SCCSID */
43 43
44/* 44/*
45 * tty.c: tty interface stuff 45 * tty.c: tty interface stuff
46 */ 46 */
47#include <assert.h> 47#include <assert.h>
48#include <errno.h> 48#include <errno.h>
49#include <unistd.h> /* for isatty */ 49#include <unistd.h> /* for isatty */
50#include <strings.h> /* for ffs */ 50#include <strings.h> /* for ffs */
51#include "el.h" 51#include "el.h"
52#include "tty.h" 52#include "tty.h"
53 53
@@ -914,35 +914,35 @@ tty_bind_char(EditLine *el, int force) @@ -914,35 +914,35 @@ tty_bind_char(EditLine *el, int force)
914 dmap = el->el_map.vii; 914 dmap = el->el_map.vii;
915 dalt = el->el_map.vic; 915 dalt = el->el_map.vic;
916 } else { 916 } else {
917 dmap = el->el_map.emacs; 917 dmap = el->el_map.emacs;
918 dalt = NULL; 918 dalt = NULL;
919 } 919 }
920 920
921 for (tp = tty_map; tp->nch != -1; tp++) { 921 for (tp = tty_map; tp->nch != -1; tp++) {
922 new[0] = t_n[tp->nch]; 922 new[0] = t_n[tp->nch];
923 old[0] = t_o[tp->och]; 923 old[0] = t_o[tp->och];
924 if (new[0] == old[0] && !force) 924 if (new[0] == old[0] && !force)
925 continue; 925 continue;
926 /* Put the old default binding back, and set the new binding */ 926 /* Put the old default binding back, and set the new binding */
927 key_clear(el, map, old); 927 keymacro_clear(el, map, old);
928 map[UC(old[0])] = dmap[UC(old[0])]; 928 map[UC(old[0])] = dmap[UC(old[0])];
929 key_clear(el, map, new); 929 keymacro_clear(el, map, new);
930 /* MAP_VI == 1, MAP_EMACS == 0... */ 930 /* MAP_VI == 1, MAP_EMACS == 0... */
931 map[UC(new[0])] = tp->bind[el->el_map.type]; 931 map[UC(new[0])] = tp->bind[el->el_map.type];
932 if (dalt) { 932 if (dalt) {
933 key_clear(el, alt, old); 933 keymacro_clear(el, alt, old);
934 alt[UC(old[0])] = dalt[UC(old[0])]; 934 alt[UC(old[0])] = dalt[UC(old[0])];
935 key_clear(el, alt, new); 935 keymacro_clear(el, alt, new);
936 alt[UC(new[0])] = tp->bind[el->el_map.type + 1]; 936 alt[UC(new[0])] = tp->bind[el->el_map.type + 1];
937 } 937 }
938 } 938 }
939} 939}
940 940
941 941
942/* tty_rawmode(): 942/* tty_rawmode():
943 * Set terminal into 1 character at a time mode. 943 * Set terminal into 1 character at a time mode.
944 */ 944 */
945protected int 945protected int
946tty_rawmode(EditLine *el) 946tty_rawmode(EditLine *el)
947{ 947{
948 948