aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2002-12-03 16:01:14 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2002-12-03 16:01:14 +0000
commit2d31da386cc08e66994cdc41d7ec729b64e60211 (patch)
treea9129fe58fd142dee0f0cbc0d01b7e685e71b061
parent[w3m-dev 03514] Effect of tab title (diff)
downloadw3m-2d31da386cc08e66994cdc41d7ec729b64e60211.tar.gz
w3m-2d31da386cc08e66994cdc41d7ec729b64e60211.zip
[w3m-dev 03515] 2 stroke keybinding
* func.c (setKeymap): add map K_MULTI support (getKey2): added (getKey): rewrite to use getKey2() * func.h (K_MULTI): added (MULTI_KEY): added * funcname.tab (MULTIMAP): added * main.c (escKeyProc): added (escmap): rewrite to use escKeyProc() (escbmap): rewrite to use escKeyProc() (escdmap): rewrite to use escKeyProc() (multimap): added * proto.h (multimap): added From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat (limited to '')
-rw-r--r--ChangeLog19
-rw-r--r--func.c120
-rw-r--r--func.h4
-rw-r--r--funcname.tab3
-rw-r--r--main.c61
-rw-r--r--proto.h3
6 files changed, 173 insertions, 37 deletions
diff --git a/ChangeLog b/ChangeLog
index 33abf12..bbbafbc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2002-12-04 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+ * [w3m-dev 03515] 2 stroke keybinding
+ * func.c (setKeymap): add map
+ K_MULTI support
+ (getKey2): added
+ (getKey): rewrite to use getKey2()
+ * func.h (K_MULTI): added
+ (MULTI_KEY): added
+ * funcname.tab (MULTIMAP): added
+ * main.c (escKeyProc): added
+ (escmap): rewrite to use escKeyProc()
+ (escbmap): rewrite to use escKeyProc()
+ (escdmap): rewrite to use escKeyProc()
+ (multimap): added
+ * proto.h (multimap): added
+
+2002-12-04 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+
* [w3m-dev 03514] Effect of tab title
* display.c (redrawNLine): rewrite, do without clrtoeolx()
@@ -5366,4 +5383,4 @@ a * [w3m-dev 03276] compile error on EWS4800
* release-0-2-1
* import w3m-0.2.1
-$Id: ChangeLog,v 1.579 2002/12/03 15:52:37 ukai Exp $
+$Id: ChangeLog,v 1.580 2002/12/03 16:01:14 ukai Exp $
diff --git a/func.c b/func.c
index 41d3005..70f8083 100644
--- a/func.c
+++ b/func.c
@@ -1,4 +1,4 @@
-/* $Id: func.c,v 1.17 2002/11/25 17:03:45 ukai Exp $ */
+/* $Id: func.c,v 1.18 2002/12/03 16:01:31 ukai Exp $ */
/*
* w3m func.c
*/
@@ -20,6 +20,7 @@ static struct stat current_keymap_file;
void
setKeymap(char *p, int lineno, int verbose)
{
+ unsigned char *map = NULL;
char *s, *emsg;
int c, f;
@@ -47,14 +48,56 @@ setKeymap(char *p, int lineno, int verbose)
disp_message_nsec(emsg, FALSE, 1, TRUE, FALSE);
return;
}
- if (c & K_ESCD)
- EscDKeymap[c ^ K_ESCD] = f;
- else if (c & K_ESCB)
- EscBKeymap[c ^ K_ESCB] = f;
- else if (c & K_ESC)
- EscKeymap[c ^ K_ESC] = f;
- else
- GlobalKeymap[c] = f;
+ if (c & K_MULTI) {
+ unsigned char **mmap = NULL;
+ int i, j, m = MULTI_KEY(c);
+
+ if (m & K_ESCD)
+ map = EscDKeymap;
+ else if (m & K_ESCB)
+ map = EscBKeymap;
+ else if (m & K_ESC)
+ map = EscKeymap;
+ else
+ map = GlobalKeymap;
+ if (map[m & 0x7F] == FUNCNAME_multimap)
+ mmap = (unsigned char **)getKeyData(m);
+ else
+ map[m & 0x7F] = FUNCNAME_multimap;
+ if (!mmap) {
+ mmap = New_N(unsigned char *, 4);
+ for (i = 0; i < 4; i++) {
+ mmap[i] = New_N(unsigned char, 128);
+ for (j = 0; j < 128; j++)
+ mmap[i][j] = FUNCNAME_nulcmd;
+ }
+ mmap[0][ESC_CODE] = FUNCNAME_escmap;
+ mmap[1]['['] = FUNCNAME_escbmap;
+ mmap[1]['O'] = FUNCNAME_escbmap;
+ }
+ if (keyData == NULL)
+ keyData = newHash_iv(KEYDATA_HASH_SIZE);
+ putHash_iv(keyData, m, (void *)mmap);
+ if (c & K_ESCD)
+ map = mmap[3];
+ else if (c & K_ESCB)
+ map = mmap[2];
+ else if (c & K_ESC)
+ map = mmap[1];
+ else
+ map = mmap[0];
+ }
+ else {
+ if (c & K_ESCD)
+ map = EscDKeymap;
+ else if (c & K_ESCB)
+ map = EscBKeymap;
+ else if (c & K_ESC)
+ map = EscKeymap;
+ else
+ map = GlobalKeymap;
+ }
+ map[c & 0x7F] = f;
s = getQWord(&p);
if (*s) {
if (keyData == NULL)
@@ -134,22 +177,31 @@ getKeyData(int key)
return (char *)getHash_iv(keyData, key, NULL);
}
-int
-getKey(char *s)
+static int
+getKey2(char **str)
{
+ char *s = *str;
int c, esc = 0, ctrl = 0;
if (s == NULL || *s == '\0')
return -1;
- if (strcasecmp(s, "UP") == 0) /* ^[[A */
+ if (strcasecmp(s, "UP") == 0) { /* ^[[A */
+ *str = s + 2;
return K_ESCB | 'A';
- else if (strcasecmp(s, "DOWN") == 0) /* ^[[B */
+ }
+ else if (strcasecmp(s, "DOWN") == 0) { /* ^[[B */
+ *str = s + 4;
return K_ESCB | 'B';
- else if (strcasecmp(s, "RIGHT") == 0) /* ^[[C */
+ }
+ else if (strcasecmp(s, "RIGHT") == 0) { /* ^[[C */
+ *str = s + 5;
return K_ESCB | 'C';
- else if (strcasecmp(s, "LEFT") == 0) /* ^[[D */
+ }
+ else if (strcasecmp(s, "LEFT") == 0) { /* ^[[D */
+ *str = s + 4;
return K_ESCB | 'D';
+ }
if (strncasecmp(s, "ESC-", 4) == 0 || strncasecmp(s, "ESC ", 4) == 0) { /* ^[ */
s += 4;
@@ -192,6 +244,7 @@ getKey(char *s)
}
if (ctrl) {
+ *str = s + 1;
if (*s >= '@' && *s <= '_') /* ^@ .. ^_ */
return esc | (*s - '@');
else if (*s >= 'a' && *s <= 'z') /* ^a .. ^z */
@@ -209,21 +262,30 @@ getKey(char *s)
c = c * 10 + (int)(*s - '0');
s++;
}
+ *str = s + 1;
if (*s == '~')
return K_ESCD | c;
else
return -1;
}
- if (strncasecmp(s, "SPC", 3) == 0) /* ' ' */
+ if (strncasecmp(s, "SPC", 3) == 0) { /* ' ' */
+ *str = s + 3;
return esc | ' ';
- else if (strncasecmp(s, "TAB", 3) == 0) /* ^i */
+ }
+ else if (strncasecmp(s, "TAB", 3) == 0) { /* ^i */
+ *str = s + 3;
return esc | '\t';
- else if (strncasecmp(s, "DEL", 3) == 0) /* ^? */
+ }
+ else if (strncasecmp(s, "DEL", 3) == 0) { /* ^? */
+ *str = s + 3;
return esc | DEL_CODE;
+ }
if (*s == '\\' && *(s + 1) != '\0') {
- switch (*(s + 1)) {
+ s++;
+ *str = s + 1;
+ switch (*s) {
case 'a': /* ^g */
return esc | CTRL_G;
case 'b': /* ^h */
@@ -244,12 +306,32 @@ getKey(char *s)
return -1;
}
}
+ *str = s + 1;
if (IS_ASCII(*s)) /* Ascii */
return esc | *s;
else
return -1;
}
+int
+getKey(char *s)
+{
+ int c, c2;
+
+ c = getKey2(&s);
+ if (c < 0)
+ return -1;
+ if (*s == ' ' || *s == '-')
+ s++;
+ if (*s) {
+ c2 = getKey2(&s);
+ if (c2 < 0)
+ return -1;
+ c = K_MULTI | (c << 16) | c2;
+ }
+ return c;
+}
+
char *
getWord(char **str)
{
diff --git a/func.h b/func.h
index 49107a7..dfd61fd 100644
--- a/func.h
+++ b/func.h
@@ -1,4 +1,4 @@
-/* $Id: func.h,v 1.3 2001/12/10 17:02:44 ukai Exp $ */
+/* $Id: func.h,v 1.4 2002/12/03 16:01:33 ukai Exp $ */
/*
* w3m func.h
*/
@@ -14,6 +14,8 @@
#define K_ESC 0x100
#define K_ESCB 0x200
#define K_ESCD 0x400
+#define K_MULTI 0x10000000
+#define MULTI_KEY(c) (((c) >> 16) & 0x77F)
typedef struct _FuncList {
char *id;
diff --git a/funcname.tab b/funcname.tab
index 795dfff..61de0da 100644
--- a/funcname.tab
+++ b/funcname.tab
@@ -1,4 +1,4 @@
-# $Id: funcname.tab,v 1.15 2002/11/25 16:57:17 ukai Exp $
+# $Id: funcname.tab,v 1.16 2002/12/03 16:01:35 ukai Exp $
# macro name function name
#----------------------------
@@@ nulcmd
@@ -68,6 +68,7 @@ MOVE_RIGHT1 movR1
MOVE_UP movU
MOVE_UP1 movU1
MSGS msgs
+MULTIMAP multimap
NEW_TAB newT
NEXT nextBf
NEXT_DOWN nextD
diff --git a/main.c b/main.c
index 9fe1825..a0d1cc9 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.156 2002/11/26 18:03:27 ukai Exp $ */
+/* $Id: main.c,v 1.157 2002/12/03 16:01:37 ukai Exp $ */
#define MAINPROGRAM
#include "fm.h"
#include <signal.h>
@@ -1183,15 +1183,41 @@ pcmap(void)
}
#endif
+static void
+escKeyProc(int c, int esc, unsigned char *map)
+{
+ if (CurrentKey >= 0 && CurrentKey & K_MULTI) {
+ unsigned char **mmap;
+ mmap = (unsigned char **)getKeyData(MULTI_KEY(CurrentKey));
+ if (!mmap)
+ return;
+ switch (esc) {
+ case K_ESCD:
+ map = mmap[3];
+ break;
+ case K_ESCB:
+ map = mmap[2];
+ break;
+ case K_ESC:
+ map = mmap[1];
+ break;
+ default:
+ map = mmap[0];
+ break;
+ }
+ esc |= (CurrentKey & ~0xFFFF);
+ }
+ CurrentKey = esc | c;
+ w3mFuncList[(int)map[c]].func();
+}
+
void
escmap(void)
{
char c;
c = getch();
- if (IS_ASCII(c)) {
- CurrentKey = K_ESC | c;
- w3mFuncList[(int)EscKeymap[(int)c]].func();
- }
+ if (IS_ASCII(c))
+ escKeyProc((int)c, K_ESC, EscKeymap);
}
void
@@ -1199,29 +1225,36 @@ escbmap(void)
{
char c;
c = getch();
-
- if (IS_DIGIT(c))
+ if (IS_DIGIT(c)) {
escdmap(c);
- else if (IS_ASCII(c)) {
- CurrentKey = K_ESCB | c;
- w3mFuncList[(int)EscBKeymap[(int)c]].func();
+ return;
}
+ if (IS_ASCII(c))
+ escKeyProc((int)c, K_ESCB, EscBKeymap);
}
void
escdmap(char c)
{
int d;
-
d = (int)c - (int)'0';
c = getch();
if (IS_DIGIT(c)) {
d = d * 10 + (int)c - (int)'0';
c = getch();
}
- if (c == '~') {
- CurrentKey = K_ESCD | d;
- w3mFuncList[(int)EscDKeymap[d]].func();
+ if (c == '~')
+ escKeyProc((int)d, K_ESCD, EscDKeymap);
+}
+
+void
+multimap(void)
+{
+ char c;
+ c = getch();
+ if (IS_ASCII(c)) {
+ CurrentKey = K_MULTI | (CurrentKey << 16) | c;
+ escKeyProc((int)c, 0, NULL);
}
}
diff --git a/proto.h b/proto.h
index 3ba9fba..75f0363 100644
--- a/proto.h
+++ b/proto.h
@@ -1,4 +1,4 @@
-/* $Id: proto.h,v 1.63 2002/11/26 17:05:25 ukai Exp $ */
+/* $Id: proto.h,v 1.64 2002/12/03 16:01:44 ukai Exp $ */
/*
* This file was automatically generated by version 1.7 of cextract.
* Manual editing not recommended.
@@ -313,6 +313,7 @@ extern void pcmap(void);
extern void escmap(void);
extern void escbmap(void);
extern void escdmap(char c);
+extern void multimap(void);
extern char *inputLineHistSearch(char *prompt, char *def_str, int flag,
Hist *hist, int (*incfunc) (int ch, Str buf,
Lineprop *prop));