w3m

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

commit 766a28a5efaee3d536eb87ed3174bd9d64ee23be
parent cff933929ac9fc072cf7c2d51febcf4a850d17ed
Author: ukai <ukai>
Date:   Sun, 23 Dec 2001 14:44:00 +0000

[w3m-dev 02700] search refactoring
From: Fumitoshi UKAI  <ukai@debian.or.jp>

Diffstat:
MChangeLog | 14++++++++++++++
Mfm.h | 5+++++
Mmain.c | 121++++++++++++++++++++++++++++++++++++-------------------------------------------
Msearch.c | 24++++++++++--------------
4 files changed, 84 insertions(+), 80 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -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 diff --git a/fm.h b/fm.h @@ -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, diff --git a/main.c b/main.c @@ -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 */ diff --git a/search.c b/search.c @@ -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; }