diff options
author | Fumitoshi UKAI <ukai@debian.or.jp> | 2001-12-23 14:44:00 +0000 |
---|---|---|
committer | Fumitoshi UKAI <ukai@debian.or.jp> | 2001-12-23 14:44:00 +0000 |
commit | ad72e6e16411a4c9dfa739d7231d412521621acf (patch) | |
tree | 6c29f760832a50596187131b57fc10797a21e75b | |
parent | run make indent (diff) | |
download | w3m-ad72e6e16411a4c9dfa739d7231d412521621acf.tar.gz w3m-ad72e6e16411a4c9dfa739d7231d412521621acf.zip |
[w3m-dev 02700] search refactoring
From: Fumitoshi UKAI <ukai@debian.or.jp>
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | fm.h | 7 | ||||
-rw-r--r-- | main.c | 123 | ||||
-rw-r--r-- | search.c | 26 |
4 files changed, 88 insertions, 84 deletions
@@ -1,5 +1,19 @@ 2001-12-23 Fumitoshi UKAI <ukai@debian.or.jp> + * [w3m-dev 02700] search refactoring + * based on http://www.nmn.jp/~hidai/software/w3m/ + * fm.h: add SR_* constants, result value for search + * main.c (srchcore): added + * main.c (disp_srchresult): added + * main.c (srch): added + * main.c (srchfor): use srch() + * main.c (srchbak): use srch() + * main.c (srch_nxtprv): use srchcore() & disp_srch_result() + * search.c (forwardSearch): return SR_* result value + * search.c (backwardSearch): ditto + +2001-12-23 Fumitoshi UKAI <ukai@debian.or.jp> + * [w3m-dev 02699] initialization too late * main.c (MAIN): initializations moved before arg processing * debian bug closes: Bug##102445: ignores SIGWINCH while downloading @@ -1443,4 +1457,4 @@ * release-0-2-1 * import w3m-0.2.1 -$Id: ChangeLog,v 1.162 2001/12/23 14:24:22 ukai Exp $ +$Id: ChangeLog,v 1.163 2001/12/23 14:44:00 ukai Exp $ @@ -1,4 +1,4 @@ -/* $Id: fm.h,v 1.29 2001/12/14 17:35:08 ukai Exp $ */ +/* $Id: fm.h,v 1.30 2001/12/23 14:44:00 ukai Exp $ */ /* * w3m: WWW wo Miru utility * @@ -184,6 +184,11 @@ void bzero(void *, int); #define LB_N_SOURCE LB_SOURCE #define MAX_LB 5 +/* Search Result */ +#define SR_FOUND 0x1 +#define SR_NOTFOUND 0x2 +#define SR_WRAPPED 0x4 + #ifdef MAINPROGRAM int REV_LB[MAX_LB] = { LB_N_FRAME, LB_FRAME, LB_N_INFO, LB_INFO, LB_N_SOURCE, @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.41 2001/12/23 14:24:22 ukai Exp $ */ +/* $Id: main.c,v 1.42 2001/12/23 14:44:00 ukai Exp $ */ #define MAINPROGRAM #include "fm.h" #include <signal.h> @@ -1308,78 +1308,82 @@ rdrwSc(void) displayBuffer(Currentbuf, B_FORCE_REDRAW); } -/* Search regular expression forward */ -void -srchfor(void) +/* search by regular expression */ +static int +srchcore(char *str, int (*func) (Buffer *, char *)) { MySignalHandler(*prevtrap) (); - char *str; - int i, n = searchKeyNum(); - volatile int wrapped = 0; + volatile int i, result = SR_NOTFOUND; + + if (str != NULL && str != SearchString) + SearchString = str; + if (SearchString == NULL || *SearchString == '\0') + return SR_NOTFOUND; - str = inputStrHist("Forward: ", NULL, TextHist); - if (str != NULL && *str == '\0') - str = SearchString; - if (str == NULL || *str == '\0') { - displayBuffer(Currentbuf, B_NORMAL); - return; - } - SearchString = str; prevtrap = signal(SIGINT, intTrap); crmode(); if (SETJMP(IntReturn) == 0) - for (i = 0; i < n; i++) - wrapped = forwardSearch(Currentbuf, SearchString); + for (i = 0; i < PREC_NUM; i++) + result = func(Currentbuf, SearchString); signal(SIGINT, prevtrap); term_raw(); displayBuffer(Currentbuf, B_NORMAL); onA(); - if (wrapped) { - disp_message("Search wrapped", FALSE); - } - searchRoutine = forwardSearch; + return result; } -/* Search regular expression backward */ void -srchbak(void) +disp_srchresult(int result, char *prompt, char *str) +{ + if (str == NULL) + str = ""; + if (result & SR_NOTFOUND) + disp_message(Sprintf("Not found: %s", str)->ptr, FALSE); + else if (result & SR_WRAPPED) + disp_message(Sprintf("Search wrapped: %s", str)->ptr, FALSE); + else if (show_srch_str) + disp_message(Sprintf("%s%s", prompt, str)->ptr, FALSE); +} + +void +srch(int (*func) (Buffer *, char *), char *prompt) { - MySignalHandler(*prevtrap) (); char *str; - int i, n = searchKeyNum(); - volatile int wrapped = 0; + int result; - str = inputStrHist("Backward: ", NULL, TextHist); + str = inputStrHist(prompt, NULL, TextHist); if (str != NULL && *str == '\0') str = SearchString; - if (str == NULL || *str == '\0') { - displayBuffer(Currentbuf, B_NORMAL); + if (str == NULL) return; - } - SearchString = str; - prevtrap = signal(SIGINT, intTrap); - crmode(); - if (SETJMP(IntReturn) == 0) - for (i = 0; i < n; i++) - wrapped = backwardSearch(Currentbuf, SearchString); - signal(SIGINT, prevtrap); - term_raw(); - displayBuffer(Currentbuf, B_NORMAL); - onA(); - if (wrapped) { - disp_message("Search wrapped", FALSE); - } - searchRoutine = backwardSearch; + result = srchcore(str, func); + disp_srchresult(result, prompt, str); + searchRoutine = func; +} + +/* Search regular expression forward */ +void +srchfor(void) +{ + srch(forwardSearch, "Forward: "); +} + +/* Search regular expression backward */ +void +srchbak(void) +{ + srch(backwardSearch, "Backward: "); } static void -srch_nxtprv(volatile int reverse) +srch_nxtprv(int reverse) { - int i; - volatile int wrapped = 0; + int result; + /* *INDENT-OFF* */ static int (*routine[2]) (Buffer *, char *) = { - forwardSearch, backwardSearch}; - MySignalHandler(*prevtrap) (); + forwardSearch, backwardSearch + }; + /* *INDENT-ON* */ if (searchRoutine == NULL) { disp_message("No previous regular expression", TRUE); @@ -1389,24 +1393,9 @@ srch_nxtprv(volatile int reverse) reverse = 1; if (searchRoutine == backwardSearch) reverse ^= 1; - prevtrap = signal(SIGINT, intTrap); - crmode(); - if (SETJMP(IntReturn) == 0) - for (i = 0; i < PREC_NUM; i++) - wrapped = (*routine[reverse]) (Currentbuf, SearchString); - signal(SIGINT, prevtrap); - term_raw(); - displayBuffer(Currentbuf, B_NORMAL); - onA(); - if (wrapped) { - disp_message("Search wrapped", FALSE); - } - else if (show_srch_str) { - disp_message(Sprintf("%s%s", - routine[reverse] == - forwardSearch ? "Forward: " : "Backward: ", - SearchString)->ptr, FALSE); - } + result = srchcore(SearchString, routine[reverse]); + disp_srchresult(result, (reverse ? "Backward: " : "Forward: "), + SearchString); } /* Search next matching */ @@ -1,4 +1,4 @@ -/* $Id: search.c,v 1.4 2001/11/24 02:01:26 ukai Exp $ */ +/* $Id: search.c,v 1.5 2001/12/23 14:44:00 ukai Exp $ */ #include "fm.h" #include "regex.h" @@ -12,12 +12,11 @@ forwardSearch(Buffer *buf, char *str) if ((p = regexCompile(str, IgnoreCase)) != NULL) { message(p, 0, 0); - return FALSE; + return SR_NOTFOUND; } l = begin = buf->currentLine; if (l == NULL) { - disp_message("Not found", FALSE); - return FALSE; + return SR_NOTFOUND; } pos = buf->pos + 1; #ifdef JP_CHARSET @@ -28,7 +27,7 @@ forwardSearch(Buffer *buf, char *str) matchedPosition(&first, &last); buf->pos = first - l->lineBuf; arrangeCursor(buf); - return FALSE; + return SR_FOUND; } for (l = l->next;; l = l->next) { if (l == NULL) { @@ -61,13 +60,12 @@ forwardSearch(Buffer *buf, char *str) buf->currentLine = l; gotoLine(buf, l->linenumber); arrangeCursor(buf); - return wrapped; + return SR_FOUND | (wrapped ? SR_WRAPPED : 0); } if (wrapped && l == begin) /* no match */ break; } - disp_message("Not found", FALSE); - return FALSE; + return SR_NOTFOUND; } int @@ -80,12 +78,11 @@ backwardSearch(Buffer *buf, char *str) if ((p = regexCompile(str, IgnoreCase)) != NULL) { message(p, 0, 0); - return FALSE; + return SR_NOTFOUND; } l = begin = buf->currentLine; if (l == NULL) { - disp_message("Not found", FALSE); - return FALSE; + return SR_NOTFOUND; } if (buf->pos > 0) { pos = buf->pos - 1; @@ -112,7 +109,7 @@ backwardSearch(Buffer *buf, char *str) if (found) { buf->pos = found - l->lineBuf; arrangeCursor(buf); - return FALSE; + return SR_FOUND; } } for (l = l->prev;; l = l->prev) { @@ -146,11 +143,10 @@ backwardSearch(Buffer *buf, char *str) buf->currentLine = l; gotoLine(buf, l->linenumber); arrangeCursor(buf); - return wrapped; + return SR_FOUND | (wrapped ? SR_WRAPPED : 0); } if (wrapped && l == begin) /* no match */ break; } - disp_message("Not found", FALSE); - return FALSE; + return SR_NOTFOUND; } |