Removed some unnecessary #includes and dll dependencies.
[wine/multimedia.git] / programs / notepad / search.c
blob3be3fbfde849a10a811d4e8d34e286e403b56c0c
1 /*
2 * Notepad (search.c)
3 * Copyright (C) 1999 by Marcel Baur
4 * To be distributed under the Wine license
6 * This file features Heuristic Boyer-Moore Text Search
8 * Always: - Buf is the Buffer containing the whole text
9 * ======= - SP is the Search Pattern, which has to be found in Buf.
13 #include <windows.h>
15 #define CHARSETSIZE 255
17 int delta[CHARSETSIZE];
19 /* rightmostpos: return rightmost position of ch in szSP (or -1) */
20 int rightmostpos(char ch, LPSTR szSP, int nSPLen) {
21 int i = nSPLen;
22 while ((i>0) & (szSP[i]!=ch)) i--;
23 return(i);
26 /* setup_delta: setup delta1 cache */
27 void setup_delta(LPSTR szSP, int nSPLen) {
28 int i;
30 for (i=0; i<CHARSETSIZE; i++) {
31 delta[i] = nSPLen;
34 for (i=0; i<nSPLen; i++) {
35 delta[(int)szSP[i]] = (nSPLen - rightmostpos(szSP[i], szSP, nSPLen));
39 int bm_search(LPSTR szBuf, int nBufLen, LPSTR szSP, int nSPLen) {
40 int i = nSPLen;
41 int j = nSPLen;
43 do {
44 if ((szBuf[i] = szSP[j])) {
45 i--; j--;
46 } else {
47 if ((nSPLen-j+1) > delta[(int)szBuf[i]]) {
48 i+= (nSPLen-j+1);
49 } else {
50 i+= delta[(int)szBuf[i]];
53 } while (j>0 && i<=nBufLen);
54 return(i+1);