@@ -219,58 +219,52 @@ int utils_searchexp(const char *haystack, const char *needleslist, const char **
219219static int _utils_searchexp (const char * haystack , const char * needleslist , int ignore_case , const char * * rest )
220220{
221221 int ret = EREJECT ;
222+ if (needleslist == NULL || needleslist [0 ] == '\0' )
223+ return ret ;
222224 if (haystack != NULL )
223225 {
224226 int i = -1 ;
225227 const char * needle = needleslist ;
226228 while (needle != NULL )
227229 {
228- i = -1 ;
230+ i = 0 ;
229231 ret = ECONTINUE ;
230- int wildcard = 1 ;
232+ const char * wildcard = & ( haystack [ i ]) ;
231233 if (* needle == '^' )
232234 {
233- wildcard = 0 ;
235+ wildcard = NULL ;
236+ needle ++ ;
234237 }
235238 const char * needle_entry = needle ;
236239 do
237240 {
241+ utils_dbg ("wildcard %s needle %s, haystack %s" , wildcard , needle , & haystack [i ]);
242+ char hay = haystack [i ];
238243 if (* needle == '*' )
239244 {
240- wildcard = 1 ;
245+ wildcard = & ( haystack [ i ]) ;
241246 needle ++ ;
242247 }
243- i ++ ;
244- char hay = haystack [i ];
245248 // lowercase
246249 if (ignore_case && hay > 0x40 && hay < 0x5b )
247250 hay += 0x20 ;
248- utils_dbg ("wildcard %d, needle %s, haystack %s" , wildcard , needle , & haystack [i ]);
249- if (!wildcard )
251+ if (wildcard == NULL )
250252 {
251- needle ++ ;
252253 char lneedle = * needle ;
253254 if (ignore_case && lneedle > 0x40 && lneedle < 0x5b )
254255 lneedle += 0x20 ;
255- if (* needle == ',' || * needle == '\0' || * needle == '$' )
256- {
257- utils_dbg ("end of needle, hay %c" , hay );
258- break ;
259- }
260- else if (lneedle != hay && * needle != '*' )
256+ if (lneedle != hay )
261257 {
262258 utils_dbg ("end of needle %c, hay %c" ,lneedle , hay );
263259 needle = needle_entry ;
264260 ret = EREJECT ;
265- if (* needle == '^' )
266- {
267- break ;
268- }
261+ break ;
269262 }
270263 else if (lneedle == hay )
271264 {
272265 ret = ESUCCESS ;
273266 }
267+ needle ++ ;
274268 }
275269 else
276270 {
@@ -281,13 +275,16 @@ static int _utils_searchexp(const char *haystack, const char *needleslist, int i
281275 ret = ESUCCESS ;
282276 if (lneedle == hay )
283277 {
284- wildcard = 0 ;
285- }
286- else if (* needle == ',' || * needle == '\0' )
287- {
288- break ;
278+ wildcard = NULL ;
279+ needle ++ ;
289280 }
290281 }
282+ i ++ ;
283+ if (* needle == ',' || * needle == '\0' || * needle == '$' )
284+ {
285+ utils_dbg ("end of needle %c, hay %c" , * needle , hay );
286+ break ;
287+ }
291288 }
292289 while (haystack [i ] != '\0' );
293290 if (* needle == '*' && haystack [i ] != '\0' )
@@ -305,8 +302,8 @@ static int _utils_searchexp(const char *haystack, const char *needleslist, int i
305302 {
306303 if (* needle == ',' || * needle == '\0' || * needle == '$' )
307304 {
308- if (wildcard && (rest != NULL ))
309- * rest = & haystack [ i - 1 ] ;
305+ if (wildcard && (* needle != '$' ) && ( rest != NULL ))
306+ * rest = wildcard ;
310307 break ;
311308 }
312309 else if (* needle != '*' )
0 commit comments