2 FAR manager incremental search plugin, search as you type in editor.
3 Copyright (C) 1999-2019, Stanislav V. Mekhanoshin
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
20 char aUpcaseTable
[256];
22 void InitUpcaseTable(int nTableNum
, BOOL bAnsiMode
)
24 #if !defined(WINPORT_DIRECT)
25 if (nTableNum
== -1) { /* OEM text */
27 for (i
= 0; i
< sizeof(aUpcaseTable
); i
++)
28 aUpcaseTable
[i
] = (char)i
;
30 OemToCharBuff(aUpcaseTable
, aUpcaseTable
, sizeof(aUpcaseTable
));
31 CharUpperBuff(aUpcaseTable
, sizeof(aUpcaseTable
));
33 CharToOemBuff(aUpcaseTable
, aUpcaseTable
, sizeof(aUpcaseTable
));
35 struct CharTableSet cts
;
37 apiCharTable(nTableNum
, (char *)&cts
, sizeof(struct CharTableSet
));
38 memcpy(aUpcaseTable
, cts
.UpperTable
, sizeof(aUpcaseTable
));
43 #if !defined(__WATCOMC__) && !defined(WINPORT_DIRECT)
44 void UpperCase(char *sDest
, const char *sSrc
, size_t nLength
)
46 /* while(nLength--)sDest[nLength]=aUpcaseTable[sSrc[nLenhth]]; */
56 mov ebx
, offset aUpcaseTable
57 Next
: mov al
, [esi
][ecx
]
66 #if defined(WINPORT_DIRECT)
67 void UpperCase(TCHAR
*sDest
, const TCHAR
*sSrc
, size_t nLen
)
70 memcpy(sDest
, sSrc
, nLen
* sizeof(sDest
[0]));
71 WINPORT(CharUpperBuff
)(sDest
, nLen
);
76 extern char ToUpper(char cByte
);
77 #pragma aux ToUpper parm[al] value[al] modify exact[eax ebx] nomemory = \
78 "mov ebx, offset aUpcaseTable" \
80 #elif !defined(WINPORT_DIRECT)
81 static __inline
char ToUpper(char cByte
)
83 /* return aUpcaseTable[(unsigned char)cByte]; */
86 mov ebx
, offset aUpcaseTable
91 static __inline TCHAR
ToUpper(TCHAR cByte
)
93 #if defined(WINPORT_DIRECT)
96 return aUpcaseTable
[(unsigned char)cByte
];
101 /* Pattern matching */
103 #if defined(WINPORT_DIRECT)
104 #define CHAR_MIN_T unsigned short
105 #define CHAR_MAX_V USHRT_MAX
107 #define CHAR_MIN_T unsigned char
108 #define CHAR_MAX_V UCHAR_MAX
111 static const TCHAR
*pattern
;
112 static size_t skip
[CHAR_MAX_V
+ 1];
114 static void PreInitSkipTable(const TCHAR
*sPattern
)
116 size_t *s_p
= skip
+ CHAR_MAX_V
;
122 } while (s_p
-- > skip
);
125 void SetSubstringPatternL(const TCHAR
*sPattern
)
129 PreInitSkipTable(sPattern
);
130 for (i
= 0; i
< (size_t)nLen
; i
++)
131 skip
[(CHAR_MIN_T
)pattern
[i
]] = nLen
- 1 - i
;
134 void SetSubstringPatternR(const TCHAR
*sPattern
)
138 PreInitSkipTable(sPattern
);
139 for (i
= nLen
; (i
--);)
140 skip
[(CHAR_MIN_T
)pattern
[i
]] = i
;
143 TCHAR
*SubStringL(const TCHAR
*text
, size_t N
)
149 return (TCHAR
*)text
;
151 if ((size_t)nLen
> N
) /* If pattern is longer than the text string. */
154 p_p
= pattern
+ nLen
- 1;
155 t_p
= text
+ nLen
- 1;
164 if (p_p
- pattern
== 0)
170 size_t step
= nLen
- (p_p
- pattern
);
172 if (step
< skip
[(CHAR_MIN_T
)c
])
173 step
= skip
[(CHAR_MIN_T
)c
];
175 /* If we have run out of text to search in. */
176 /* Need cast for case of large strings with 16 bit size_t... */
177 if ((unsigned long)(t_p
- text
) + step
>= (unsigned long)N
)
182 p_p
= pattern
+ nLen
- 1;
187 TCHAR
*SubStringR(const TCHAR
*text
, size_t N
)
193 return (TCHAR
*)text
;
195 if ((size_t)nLen
> N
) /* If pattern is longer than the text string. */
199 t_p
= text
+ N
- nLen
;
208 if ((int)(p_p
- pattern
) == (int)(nLen
- 1))
209 return (TCHAR
*)t_p
- nLen
+ 1;
214 size_t step
= (p_p
- pattern
) + 1;
216 if (step
< skip
[(CHAR_MIN_T
)c
])
217 step
= skip
[(CHAR_MIN_T
)c
];
219 /* If we have run out of text to search in. */
220 if (t_p
< text
+ step
)