]> mj.ucw.cz Git - libucw.git/blob - ucw/str-match.h
Doc: Updated the list of contributors
[libucw.git] / ucw / str-match.h
1 /*
2  *      UCW Library -- Generic Shell-Like Pattern Matching (currently only '?' and '*')
3  *
4  *      (c) 1997 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include <ucw/string.h>
11
12 int
13 MATCH_FUNC_NAME(const char *p, const char *s)
14 {
15   while (*p)
16     {
17       if (*p == '?' && *s)
18         p++, s++;
19       else if (*p == '*')
20         {
21           int z = p[1];
22
23           if (!z)
24             return 1;
25           if (z == '\\' && p[2])
26             z = p[2];
27           z = Convert(z);
28           for(;;)
29             {
30               while (*s && Convert(*s) != z)
31                 s++;
32               if (!*s)
33                 return 0;
34               if (MATCH_FUNC_NAME(p+1, s))
35                 return 1;
36               s++;
37             }
38         }
39       else
40         {
41           if (*p == '\\' && p[1])
42             p++;
43           if (Convert(*p++) != Convert(*s++))
44             return 0;
45         }
46     }
47   return !*s;
48 }