w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

commit 789fbaf9b510237db61834013ec0a74639db25bf
parent ec3eccea34dd521b76549c28350ef75ba7525cae
Author: ukai <ukai>
Date:   Tue,  3 Dec 2002 16:01:14 +0000

[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:
MChangeLog | 17+++++++++++++++++
Mfunc.c | 118+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Mfunc.h | 2++
Mfuncname.tab | 1+
Mmain.c | 59++++++++++++++++++++++++++++++++++++++++++++++-------------
Mproto.h | 1+
6 files changed, 167 insertions(+), 31 deletions(-)

diff --git 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() diff --git a/func.c b/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 @@ -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 @@ -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 @@ -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 @@ -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));