Added Boyer-Moore text search.

This commit is contained in:
Marcel Baur 1999-03-10 15:11:01 +00:00 committed by Alexandre Julliard
parent e562453dae
commit ebe76b73a9
3 changed files with 70 additions and 8 deletions

View File

@ -1,3 +1,7 @@
Fri Mar 5 22:14:13 1999 Marcel Baur <mbaur@g26.ethz.ch>
* NEW [search.c]
- Added Boyer-Moore text search
Sat Feb 6 20:25:25 1999 Marcel Baur <mbaur@g26.ethz.ch> Sat Feb 6 20:25:25 1999 Marcel Baur <mbaur@g26.ethz.ch>
- Added new IDS_NOTSAVED ressource (needs translation in *.rc) - Added new IDS_NOTSAVED ressource (needs translation in *.rc)
- Improved printing support (not yet complete) - Improved printing support (not yet complete)
@ -7,7 +11,7 @@ Sat Feb 6 20:25:25 1999 Marcel Baur <mbaur@g26.ethz.ch>
Thu Jan 28 18:17:08 1999 Jukka Iivonen <iivonen@iki.fi> Thu Jan 28 18:17:08 1999 Jukka Iivonen <iivonen@iki.fi>
* [Fi.rc] [main.c] [Makefile.in] * [Fi.rc] [main.c] [Makefile.in]
Added Finnish language support. - Added Finnish language support.
Sun Oct 18 14:11:42 1998 Marcel Baur <mbaur@g26.ethz.ch> Sun Oct 18 14:11:42 1998 Marcel Baur <mbaur@g26.ethz.ch>
@ -73,3 +77,4 @@ Fri Dec 05 20:51:55 1997 Marcel Baur <mbaur@g26.ethz.ch>
[README] [TODO] [ChangeLog] [README] [TODO] [ChangeLog]
- Originals by Marcel Baur - Originals by Marcel Baur

View File

@ -16,7 +16,8 @@ MOSTSRCS = \
license.c \ license.c \
main.c \ main.c \
dialog.c \ dialog.c \
language.c language.c \
search.c
# Some strings need addresses >= 0x10000 # Some strings need addresses >= 0x10000
STRINGSRCS = \ STRINGSRCS = \

56
programs/notepad/search.c Normal file
View File

@ -0,0 +1,56 @@
/*
* Notepad (search.c)
* Copyright (C) 1999 by Marcel Baur
* To be distributed under the Wine license
*
* This file features Heuristic Boyer-Moore Text Search
*
* Always: - Buf is the Buffer containing the whole text
* ======= - SP is the Search Pattern, which has to be found in Buf.
*
*/
#include <win.h>
#define CHARSETSIZE 255
int delta[CHARSETSIZE];
/* rightmostpos: return rightmost position of ch in szSP (or -1) */
int rightmostpos(char ch, LPSTR szSP, int nSPLen) {
int i = nSPLen;
while ((i>0) & (szSP[i]!=ch)) i--;
return(i);
}
/* setup_delta: setup delta1 cache */
void setup_delta(LPSTR szSP, int nSPLen) {
int i;
for (i=0; i<CHARSETSIZE; i++) {
delta[i] = nSPLen;
}
for (i=0; i<nSPLen; i++) {
delta[szSP[i]] = (nSPLen - rightmostpos(szSP[i], szSP, nSPLen));
}
}
int bm_search(LPSTR szBuf, int nBufLen, LPSTR szSP, int nSPLen) {
int i = nSPLen;
int j = nSPLen;
do {
if (szBuf[i] = szSP[j]) {
i--; j--;
} else {
if ((nSPLen-j+1) > delta[szBuf[i]]) {
i+= (nSPLen-j+1);
} else {
i+= delta[szBuf[i]];
}
}
} while (j>0 && i<=nBufLen);
return(i+1);
}