On Fri, Sep 02, 2011 at 10:41:51AM +1000, Damien Miller wrote:
> Hi,
>
> While people are excited about hacking on ksh(1) - let me add my wish:
> unrestricted multibyte character binding so I can have ctrl-left_arrow
> (^[[1;5D on my terminal) bound to backward-word and so forth.
>
> Last time I checked the code for bind could only handle a couple of
> characters after ^[
>
> -d
Here you go...
Index: Makefile
===
RCS file: /cvs/src/bin/ksh/Makefile,v
retrieving revision 1.27
diff -u -p -r1.27 Makefile
--- Makefile3 Mar 2009 20:01:01 - 1.27
+++ Makefile6 Sep 2011 22:36:26 -
@@ -10,16 +10,9 @@ DEFS=-Wall
CFLAGS+=${DEFS} -I. -I${.CURDIR} -I${.CURDIR}/../../lib/libc/gen
MAN= ksh.1 sh.1
-CLEANFILES+= emacs.out
-
LINKS= ${BINDIR}/ksh ${BINDIR}/rksh
LINKS+=${BINDIR}/ksh ${BINDIR}/sh
MLINKS=ksh.1 rksh.1
-
-.depend emacs.o: emacs.out
-
-emacs.out: emacs.c
- /bin/sh ${.CURDIR}/emacs-gen.sh ${.CURDIR}/emacs.c > emacs.out
check test:
/usr/bin/perl ${.CURDIR}/tests/th -s ${.CURDIR}/tests -p ./ksh -C \
Index: alloc.c
===
RCS file: /cvs/src/bin/ksh/alloc.c,v
retrieving revision 1.8
diff -u -p -r1.8 alloc.c
--- alloc.c 21 Jul 2008 17:30:08 - 1.8
+++ alloc.c 6 Sep 2011 22:36:26 -
@@ -62,7 +62,7 @@ alloc(size_t size, Area *ap)
{
struct link *l;
- l = malloc(sizeof(struct link) + size);
+ l = calloc(1, sizeof(struct link) + size);
if (l == NULL)
internal_errorf(1, "unable to allocate memory");
l->next = ap->freelist;
Index: emacs.c
===
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.44
diff -u -p -r1.44 emacs.c
--- emacs.c 5 Sep 2011 04:50:33 - 1.44
+++ emacs.c 6 Sep 2011 22:36:35 -
@@ -6,6 +6,9 @@
* created by Ron Natalie at BRL
* modified by Doug Kingston, Doug Gwyn, and Lou Salkind
* adapted to PD ksh by Eric Gisin
+ *
+ * partial rewrite by Marco Peereboom
+ * under the same license
*/
#include "config.h"
@@ -13,6 +16,7 @@
#include "sh.h"
#include
+#include
#include
#include
#include "edit.h"
@@ -37,12 +41,6 @@ struct x_ftab {
short xf_flags;
};
-struct x_defbindings {
- u_char xdb_func; /* XFUNC_* */
- unsigned char xdb_tab;
- unsigned char xdb_char;
-};
-
#define XF_ARG 1 /* command takes number prefix */
#defineXF_NOBIND 2 /* not allowed to bind to function */
#defineXF_PREFIX 4 /* function sets prefix */
@@ -51,10 +49,6 @@ struct x_defbindings {
#defineis_cfs(c) (c == ' ' || c == '\t' || c == '"' || c == '\'')
#defineis_mfs(c) (!(isalnum(c) || c == '_' || c == '$')) /*
Separator for motion */
-# define CHARMASK 0xFF/* 8-bit character mask */
-# define X_NTABS 3 /* normal, meta1, meta2 */
-#define X_TABSZ(CHARMASK+1)/* size of keydef tables etc */
-
/* Arguments for do_complete()
* 0 = enumerate M-= complete as much as possible and then list
* 1 = complete M-Esc
@@ -66,6 +60,17 @@ typedef enum {
CT_COMPLIST /* complete and then list (if non-exact) */
} Comp_type;
+/* keybindings */
+struct kb_entry {
+ TAILQ_ENTRY(kb_entry) entry;
+ unsigned char *seq;
+ int len;
+ struct x_ftab *ftab;
+ void*args;
+};
+TAILQ_HEAD(kb_list, kb_entry);
+struct kb_list kblist = TAILQ_HEAD_INITIALIZER(kblist);
+
/* { from 4.9 edit.h */
/*
* The following are used for my horizontal scrolling stuff
@@ -91,20 +96,18 @@ static int x_arg_defaulted;/* x_arg not
static int xlp_valid;
/* end from 4.9 edit.h } */
+static int x_tty; /* are we on a tty? */
+static int x_bind_quiet; /* be quiet when binding keys */
+static int (*x_last_command)(int);
-static int x_prefix1 = CTRL('['), x_prefix2 = CTRL('X');
static char **x_histp; /* history position */
static int x_nextcmd; /* for newline-and-next */
static char*xmp; /* mark pointer */
-static u_char x_last_command;
-static u_char (*x_tab)[X_TABSZ]; /* key definition */
-static char*(*x_atab)[X_TABSZ];/* macro definitions */
-static unsigned char x_bound[(X_TABSZ * X_NTABS + 7) / 8];
#defineKILLSIZE20
static char*killstack[KILLSIZE];
static int killsp, killtp;
-static int x_curprefix;
-static char*macroptr;
+static int x_literal_set;
+static int x_arg_set;
static int prompt_skip;
static int prompt_redraw;
@@ -123,9 +126,6 @@ static int x_search(char *, int, in
static int x_match(char *, char *);
static void