w3m

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

commit 257fdab73466d258507049821bd5aaac08444923
parent ad0751f00b0d7617231e3628a82c04f7740bdda2
Author: ukai <ukai>
Date:   Wed, 16 Jan 2002 16:49:53 +0000

[w3m-dev 02859]
* config.h.dist (DEF_MIGEMO_COMMAND): added
* configure (DEF_MIGEMO_COMMAND): added
* fm.h (migemo_command): initial value is DEF_MIGEMO_COMMAND
* main.c (migemostr): remove here, move search.c
* main.c (srchcore): dont migemostr() here
* proto.h (init_migemo): added
* rc.c (sync_with_option): init_migemo()
* search.c (init_migemo): added
* search.c (open_migemo): added
* search.c (migemostr): communicate background migemo
* search.c (forwardSearch): if regexCompile for migemostr failed,
		try original str
* search.c (backwardSearch): ditto
From: Fumitoshi UKAI  <ukai@debian.or.jp>

Diffstat:
MChangeLog | 17+++++++++++++++++
Mconfig.h.dist | 3+++
Mconfigure | 3+++
Mfm.h | 2+-
Mmain.c | 24+-----------------------
Mproto.h | 3+++
Mrc.c | 3+++
Msearch.c | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 120 insertions(+), 24 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,5 +1,22 @@ 2002-01-17 Fumitoshi UKAI <ukai@debian.or.jp> + * [w3m-dev 02859] + * config.h.dist (DEF_MIGEMO_COMMAND): added + * configure (DEF_MIGEMO_COMMAND): added + * fm.h (migemo_command): initial value is DEF_MIGEMO_COMMAND + * main.c (migemostr): remove here, move search.c + * main.c (srchcore): dont migemostr() here + * proto.h (init_migemo): added + * rc.c (sync_with_option): init_migemo() + * search.c (init_migemo): added + * search.c (open_migemo): added + * search.c (migemostr): communicate background migemo + * search.c (forwardSearch): if regexCompile for migemostr failed, + try original str + * search.c (backwardSearch): ditto + +2002-01-17 Fumitoshi UKAI <ukai@debian.or.jp> + * [w3m-dev 02855] * main.c (dispincsrch): for C-s C-s, revert some changes diff --git a/config.h.dist b/config.h.dist @@ -130,6 +130,9 @@ MODEL=Linux.i686-monster-ja #define DEF_IMAGE_VIEWER "xv" #define DEF_AUDIO_PLAYER "showaudio" +/* for USE_MIGEMO */ +#define DEF_MIGEMO_COMMAND "migemo -t egrep /usr/share/migemo/migemo-dict" + #define LIB_DIR "/usr/local/lib/w3m" #define HELP_DIR "/usr/local/lib/w3m" #define ETC_DIR "/usr/local/etc/w3m" diff --git a/configure b/configure @@ -2066,6 +2066,9 @@ $def_use_help_cgi #define DEF_IMAGE_VIEWER "$def_image_viewer" #define DEF_AUDIO_PLAYER "$def_audio_player" +/* for USE_MIGEMO */ +#define DEF_MIGEMO_COMMAND "migemo -t egrep /usr/share/migemo/migemo-dict" + #define LIB_DIR "$libdir" #define HELP_DIR "$helpdir" #define ETC_DIR "$sysconfdir" diff --git a/fm.h b/fm.h @@ -777,7 +777,7 @@ global int FoldTextarea init(FALSE); #ifdef USE_MIGEMO global int use_migemo init(FALSE); -global char *migemo_command init("migemoc"); +global char *migemo_command init(DEF_MIGEMO_COMMAND); #endif /* USE_MIGEMO */ global struct auth_cookie *Auth_cookie init(NULL); diff --git a/main.c b/main.c @@ -1333,24 +1333,6 @@ rdrwSc(void) displayBuffer(Currentbuf, B_FORCE_REDRAW); } -#ifdef USE_MIGEMO -/* Migemo: romaji --> kana+kanji in regexp */ -static char * -migemostr(char *str) -{ - FILE *f; - Str tmp; - - tmp = Strnew_m_charp(migemo_command, " ", shell_quote(str), NULL); - if (!(f = popen(tmp->ptr, "r"))) - return str; - tmp = Strfgets(f); - Strchop(tmp); - pclose(f); - return tmp->ptr; -} -#endif /* USE_MIGEMO */ - static void clear_mark(Line *l) { @@ -1369,11 +1351,7 @@ srchcore(char *str, int (*func) (Buffer *, char *)) volatile int i, result = SR_NOTFOUND; if (str != NULL && str != SearchString) - SearchString = -#ifdef USE_MIGEMO - use_migemo ? migemostr(str) : -#endif /* USE_MIGEMO */ - str; + SearchString = str; if (SearchString == NULL || *SearchString == '\0') return SR_NOTFOUND; diff --git a/proto.h b/proto.h @@ -255,6 +255,9 @@ extern char *mydirname(char *s); extern int next_status(char c, int *status); extern int read_token(Str buf, char **instr, int *status, int pre, int append); extern Str correct_irrtag(int status); +#ifdef USE_MIGEMO +extern void init_migemo(void); +#endif extern int forwardSearch(Buffer *buf, char *str); extern int backwardSearch(Buffer *buf, char *str); extern void pcmap(void); diff --git a/rc.c b/rc.c @@ -1124,6 +1124,9 @@ sync_with_option(void) #ifdef USE_EXTERNAL_URI_LOADER initURIMethods(); #endif +#ifdef USE_MIGEMO + init_migemo(); +#endif if (AcceptLang == NULL || *AcceptLang == '\0') { #if LANG == JA diff --git a/search.c b/search.c @@ -9,6 +9,75 @@ set_mark(Line *l, int pos, int epos) l->propBuf[pos] |= PE_MARK; } +#ifdef USE_MIGEMO +/* Migemo: romaji --> kana+kanji in regexp */ +static FILE *migemor, *migemow; + +void +init_migemo() +{ + if (migemor != NULL) + fclose(migemor); + if (migemow != NULL) + fclose(migemow); + migemor = migemow = NULL; +} + +static int +open_migemo(char *migemo_command) +{ + int fdr[2]; + int fdw[2]; + int pid; + if (pipe(fdr) < 0) + goto err0; + if (pipe(fdw) < 0) + goto err1; + + /* migemow:fdw[1] -|-> fdw[0]=0 {migemo} fdr[1]=1 -|-> fdr[0]:migemor */ + pid = fork(); + if (pid < 0) + goto err2; + if (pid == 0) { + /* child */ + close(fdr[0]); + close(fdw[1]); + dup2(fdw[0], 0); + dup2(fdr[1], 1); + system(migemo_command); + exit(1); + } + close(fdr[1]); + close(fdw[0]); + migemor = fdopen(fdr[0], "r"); + migemow = fdopen(fdw[1], "w"); + return 1; +err2: + close(fdw[0]); + close(fdw[1]); +err1: + close(fdr[0]); + close(fdr[1]); +err0: + use_migemo = 0; + return 0; +} + +static char * +migemostr(char *str) +{ + Str tmp = NULL; + if (migemor == NULL || migemow == NULL) + if (open_migemo(migemo_command) == 0) + return str; + fprintf(migemow, "%s\n", str); + fflush(migemow); + tmp = Strfgets(migemor); + Strchop(tmp); + return tmp->ptr; +} +#endif /* USE_MIGEMO */ + int forwardSearch(Buffer *buf, char *str) { @@ -17,6 +86,16 @@ forwardSearch(Buffer *buf, char *str) int wrapped = FALSE; int pos; +#ifdef USE_MIGEMO + if (use_migemo) { + if (((p = regexCompile(migemostr(str), IgnoreCase)) != NULL) + && ((p = regexCompile(str, IgnoreCase)) != NULL)) { + message(p, 0, 0); + return SR_NOTFOUND; + } + } + else +#endif if ((p = regexCompile(str, IgnoreCase)) != NULL) { message(p, 0, 0); return SR_NOTFOUND; @@ -85,6 +164,16 @@ backwardSearch(Buffer *buf, char *str) int wrapped = FALSE; int pos; +#ifdef USE_MIGEMO + if (use_migemo) { + if (((p = regexCompile(migemostr(str), IgnoreCase)) != NULL) + && ((p = regexCompile(str, IgnoreCase)) != NULL)) { + message(p, 0, 0); + return SR_NOTFOUND; + } + } + else +#endif if ((p = regexCompile(str, IgnoreCase)) != NULL) { message(p, 0, 0); return SR_NOTFOUND;