diff options
author | Fumitoshi UKAI <ukai@debian.or.jp> | 2002-06-01 16:50:16 +0000 |
---|---|---|
committer | Fumitoshi UKAI <ukai@debian.or.jp> | 2002-06-01 16:50:16 +0000 |
commit | fc4b6e4a93dc91fea7b64e9230d8aea9bcfe99ee (patch) | |
tree | 3aeb231080b2ce828adb5d294045ce00b06501f3 | |
parent | [w3m-dev 03196] C-w (diff) | |
download | w3m-fc4b6e4a93dc91fea7b64e9230d8aea9bcfe99ee.tar.gz w3m-fc4b6e4a93dc91fea7b64e9230d8aea9bcfe99ee.zip |
[w3m-dev 03200] Re: New configuration option ``keymap_file'' and new command ``DEFINE_KEY''
* fm.h: add <sts/stat.h>, unistd.h>
* fm.h (keymap_file): added
* func.c (keymap_initialized): added
(current_keymap_file): added
(setKeymap): added
(initKeymap): rewrite to use setKeymap()
* funcname.tab (DEFINE_KEY): added
* main.c (MAIN): initKeymap(TRUE)
(defKey): added
* proto.h (defKey): added
(setKeymap): added
(initKeymap): add force param
* rc.c (CMT_KEYMAP_FILE): added
(params3): add keymap_file
(sync_with_option): add initKeymap(FALSE)
* doc/README.func (DEFINE_KEY): added
* doc-jp/README.func: (DEFINE_KEY): added
* scripts/w3mhelp.cgi.in: add defKey
* NEWS:
func: DEFINE_KEY
rc: keymap_file
From: Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
Diffstat (limited to '')
-rw-r--r-- | ChangeLog | 27 | ||||
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | doc-jp/README.func | 1 | ||||
-rw-r--r-- | doc/README.func | 1 | ||||
-rw-r--r-- | fm.h | 6 | ||||
-rw-r--r-- | func.c | 102 | ||||
-rw-r--r-- | funcname.tab | 3 | ||||
-rw-r--r-- | main.c | 22 | ||||
-rw-r--r-- | proto.h | 6 | ||||
-rw-r--r-- | rc.c | 9 | ||||
-rw-r--r-- | scripts/w3mhelp.cgi.in | 4 |
11 files changed, 136 insertions, 47 deletions
@@ -1,3 +1,28 @@ +2002-06-02 Kiyokazu SUTO <suto@ks-and-ks.ne.jp> + + * [w3m-dev 03200] Re: New configuration option ``keymap_file'' and new command ``DEFINE_KEY'' + * fm.h: add <sts/stat.h>, unistd.h> + * fm.h (keymap_file): added + * func.c (keymap_initialized): added + (current_keymap_file): added + (setKeymap): added + (initKeymap): rewrite to use setKeymap() + * funcname.tab (DEFINE_KEY): added + * main.c (MAIN): initKeymap(TRUE) + (defKey): added + * proto.h (defKey): added + (setKeymap): added + (initKeymap): add force param + * rc.c (CMT_KEYMAP_FILE): added + (params3): add keymap_file + (sync_with_option): add initKeymap(FALSE) + * doc/README.func (DEFINE_KEY): added + * doc-jp/README.func: (DEFINE_KEY): added + * scripts/w3mhelp.cgi.in: add defKey + * NEWS: + func: DEFINE_KEY + rc: keymap_file + 2002-06-02 Hiroaki Shimotsu <shim@d5.bs1.fc.nec.co.jp> * [w3m-dev 03196] C-w @@ -3418,4 +3443,4 @@ * release-0-2-1 * import w3m-0.2.1 -$Id: ChangeLog,v 1.380 2002/06/01 16:31:54 ukai Exp $ +$Id: ChangeLog,v 1.381 2002/06/01 16:50:16 ukai Exp $ @@ -1,5 +1,7 @@ w3m 0.4? +* func: DEFINE_KEY +* rc: keymap_file * rc: use_dictcommand, dictcommand * rc: mark_all_pages * configure: -mandir diff --git a/doc-jp/README.func b/doc-jp/README.func index 6503283..ae6de37 100644 --- a/doc-jp/README.func +++ b/doc-jp/README.func @@ -8,6 +8,7 @@ CENTER_H カーソルのある位置を行の中央に移動します CENTER_V カーソルのある行を画面の中央に移動します COMMAND w3mのコマンドを実行します COOKIE クッキー一覧を表示します +DEFINE_KEY キー入力とコマンドの対応を定義します DELETE_PREVBUF 前のバッファを消去します(主に local-CGI 用) DICT_WORD 入力した単語を辞書コマンドで調べます DICT_WORD_AT カーソル位置の単語を辞書コマンドで調べます diff --git a/doc/README.func b/doc/README.func index 2c9645e..ac8949e 100644 --- a/doc/README.func +++ b/doc/README.func @@ -8,6 +8,7 @@ CENTER_H Move to the center line CENTER_V Move to the center column COMMAND Execute w3m command(s) COOKIE View cookie list +DEFINE_KEY Define a binding between a key stroke and a user command DELETE_PREVBUF Delete previous buffer (mainly for local-CGI) DICT_WORD Execute dictionary command (see README.dict) DICT_WORD_AT Execute dictionary command for word at cursor @@ -1,4 +1,4 @@ -/* $Id: fm.h,v 1.59 2002/04/24 18:29:35 ukai Exp $ */ +/* $Id: fm.h,v 1.60 2002/06/01 16:50:16 ukai Exp $ */ /* * w3m: WWW wo Miru utility * @@ -20,6 +20,8 @@ #include <string.h> #include <unistd.h> #include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #include "config.h" #include "history.h" @@ -978,6 +980,8 @@ global double image_scale init(100); #endif global int use_lessopen init(FALSE); +global char *keymap_file init(KEYMAP_FILE); + #ifdef JP_CHARSET #define is_kanji(s) (IS_KANJI1((s)[0])&&IS_KANJI2((s)[1])) #define get_mctype(s) (is_kanji(s)?PC_KANJI:GET_PCTYPE(*(s))) @@ -1,4 +1,4 @@ -/* $Id: func.c,v 1.9 2002/03/22 15:05:18 ukai Exp $ */ +/* $Id: func.c,v 1.10 2002/06/01 16:50:16 ukai Exp $ */ /* * w3m func.c */ @@ -14,20 +14,77 @@ #define KEYDATA_HASH_SIZE 16 static Hash_iv *keyData = NULL; +static char keymap_initialized; +static struct stat current_keymap_file; void -initKeymap(void) +setKeymap(char *p, int lineno, int verbose) +{ + char *s, *emsg; + int c, f; + + s = getQWord(&p); + c = getKey(s); + if (c < 0) { /* error */ + if (lineno > 0) + emsg = Sprintf("line %d: unknown key '%s'", lineno, s)->ptr; + else + emsg = Sprintf("defkey: unknown key '%s'", s)->ptr; + record_err_message(emsg); + if (verbose) + disp_message_nsec(emsg, FALSE, 1, TRUE, FALSE); + return; + } + s = getWord(&p); + f = getFuncList(s); + if (f < 0) { + if (lineno > 0) + emsg = Sprintf("line %d: invalid command '%s'", lineno, s)->ptr; + else + emsg = Sprintf("defkey: invalid command '%s'", s)->ptr; + record_err_message(emsg); + if (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; + s = getQWord(&p); + if (*s) { + if (keyData == NULL) + keyData = newHash_iv(KEYDATA_HASH_SIZE); + putHash_iv(keyData, c, (void *)s); + } +} + +void +initKeymap(int force) { FILE *kf; Str line; char *p, *s, *emsg; - int c; - int f; int lineno; int verbose = 1; + int fd; + struct stat kstat; extern int str_to_bool(char *value, int old); - if ((kf = fopen(rcFile(KEYMAP_FILE), "rt")) == NULL) + if (!force && !keymap_initialized) + return; + + if ((kf = fopen(rcFile(keymap_file), "rt")) == NULL || + ((fd = fileno(kf)) < 0 || fstat(fd, &kstat) || + (!force && keymap_initialized && + kstat.st_mtime == current_keymap_file.st_mtime && + kstat.st_dev == current_keymap_file.st_dev && + kstat.st_ino == current_keymap_file.st_ino && + kstat.st_size == current_keymap_file.st_size))) return; lineno = 0; @@ -56,40 +113,11 @@ initKeymap(void) disp_message_nsec(emsg, FALSE, 1, TRUE, FALSE); continue; } - s = getQWord(&p); - c = getKey(s); - if (c < 0) { /* error */ - emsg = Sprintf("line %d: unknown key '%s'", lineno, s)->ptr; - record_err_message(emsg); - if (verbose) - disp_message_nsec(emsg, FALSE, 1, TRUE, FALSE); - continue; - } - s = getWord(&p); - f = getFuncList(s); - if (f < 0) { - emsg = Sprintf("line %d: invalid command '%s'", lineno, s)->ptr; - record_err_message(emsg); - if (verbose) - disp_message_nsec(emsg, FALSE, 1, TRUE, FALSE); - continue; - } - 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; - s = getQWord(&p); - if (*s) { - if (keyData == NULL) - keyData = newHash_iv(KEYDATA_HASH_SIZE); - putHash_iv(keyData, c, (void *)s); - } + setKeymap(p, lineno, verbose); } fclose(kf); + current_keymap_file = kstat; + keymap_initialized = TRUE; } int diff --git a/funcname.tab b/funcname.tab index d29dd21..a56f98e 100644 --- a/funcname.tab +++ b/funcname.tab @@ -1,4 +1,4 @@ -# $Id: funcname.tab,v 1.8 2002/03/19 16:06:52 ukai Exp $ +# $Id: funcname.tab,v 1.9 2002/06/01 16:50:16 ukai Exp $ # macro name function name #---------------------------- @@@ nulcmd @@ -12,6 +12,7 @@ CENTER_H ctrCsrH CENTER_V ctrCsrV COMMAND execCmd COOKIE cooLst +DEFINE_KEY defKey DELETE_PREVBUF deletePrevBuf DICT_WORD dictword DICT_WORD_AT dictwordat @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.99 2002/04/26 16:06:34 ukai Exp $ */ +/* $Id: main.c,v 1.100 2002/06/01 16:50:16 ukai Exp $ */ #define MAINPROGRAM #include "fm.h" #include <signal.h> @@ -724,7 +724,7 @@ MAIN(int argc, char **argv, char **envp) if (w3m_backend) backend(); if (!w3m_dump) { - initKeymap(); + initKeymap(TRUE); #ifdef USE_MENU initMenu(); #endif /* MENU */ @@ -5091,3 +5091,21 @@ setAlarmEvent(int sec, short status, int cmd, void *data) } } #endif + +void +defKey(void) +{ + char *data; + + CurrentKeyData = NULL; /* not allowed in w3m-control: */ + data = searchKeyData(); + if (data == NULL || *data == '\0') { + data = inputStrHist("Key definition: ", "", TextHist); + if (data == NULL || *data == '\0') { + displayBuffer(Currentbuf, B_NORMAL); + return; + } + } + setKeymap(allocStr(data, -1), -1, TRUE); + displayBuffer(Currentbuf, B_NORMAL); +} @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.41 2002/04/24 18:29:35 ukai Exp $ */ +/* $Id: proto.h,v 1.42 2002/06/01 16:50:16 ukai Exp $ */ /* * This file was automatically generated by version 1.7 of cextract. * Manual editing not recommended. @@ -116,6 +116,7 @@ extern void setAlarmEvent(int sec, short status, int cmd, void *data); #else #define setAlarm nulcmd #endif +extern void defKey(void); extern int currentLn(Buffer *buf); extern void tmpClearBuffer(Buffer *buf); extern char *filename_extension(char *patch, int is_url); @@ -583,7 +584,8 @@ extern void clearImage(void); extern char *searchKeyData(void); -extern void initKeymap(void); +extern void setKeymap(char *p, int lineno, int verbose); +extern void initKeymap(int force); extern int getFuncList(char *id); extern int getKey(char *s); extern char *getKeyData(int key); @@ -1,4 +1,4 @@ -/* $Id: rc.c,v 1.43 2002/04/25 16:26:59 ukai Exp $ */ +/* $Id: rc.c,v 1.44 2002/06/01 16:50:16 ukai Exp $ */ /* * Initialization file etc. */ @@ -191,6 +191,8 @@ static char *config_file = NULL; #define CMT_MIGEMO_COMMAND "Migemoコマンド" #endif /* USE_MIGEMO */ +#define CMT_KEYMAP_FILE "keymapファイル" + #else /* LANG != JA */ @@ -329,6 +331,8 @@ static char *config_file = NULL; #define CMT_MIGEMO_COMMAND "Migemo command" #endif /* USE_MIGEMO */ +#define CMT_KEYMAP_FILE "keymap file" + #endif /* LANG != JA */ #define PI_TEXT 0 @@ -575,6 +579,8 @@ struct param_ptr params3[] = { NULL}, {"decode_cte", P_CHARINT, PI_ONOFF, (void *)&DecodeCTE, CMT_DECODE_CTE, NULL}, + {"keymap_file", P_STRING, PI_TEXT, (void *)&keymap_file, CMT_KEYMAP_FILE, + NULL}, {NULL, 0, 0, NULL, NULL, NULL}, }; @@ -1238,6 +1244,7 @@ sync_with_option(void) AcceptEncoding = acceptableEncoding(); if (AcceptMedia == NULL || *AcceptMedia == '\0') AcceptMedia = acceptableMimeTypes(); + initKeymap(FALSE); } void diff --git a/scripts/w3mhelp.cgi.in b/scripts/w3mhelp.cgi.in index 5a7aa64..c3cddff 100644 --- a/scripts/w3mhelp.cgi.in +++ b/scripts/w3mhelp.cgi.in @@ -1,5 +1,5 @@ #!@PERL@ -# $Id: w3mhelp.cgi.in,v 1.11 2002/01/31 17:54:58 ukai Exp $ +# $Id: w3mhelp.cgi.in,v 1.12 2002/06/01 16:50:16 ukai Exp $ if ( $^O =~ /^(ms)?(dos|win(32|nt)?)/i ) { $CYGPATH = 1; @@ -148,7 +148,7 @@ for $otherlang (@docdirs) { &show_keymap("Miscellany", split(" ", "mainMn ldhelp ldOpt cooLst ldHist msgs msToggle - wrapToggle setAlarm setOpt setEnv execsh susp qquitfm quitfm")); + wrapToggle setAlarm setOpt setEnv execsh susp qquitfm quitfm defKey")); &show_keymap("Buffer selection mode", split(" ", "buffer_next buffer_prev buffer_delete buffer_go")); |