]> mj.ucw.cz Git - libucw.git/blob - lib/patmatch.h
Added license notices to all library files which are not specific
[libucw.git] / lib / patmatch.h
1 /*
2  *      Sherlock 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 int
11 MATCH_FUNC_NAME(byte *p, byte *s)
12 {
13   while (*p)
14     {
15       if (*p == '?' && *s)
16         p++, s++;
17       else if (*p == '*')
18         {
19           int z = p[1];
20
21           if (!z)
22             return 1;
23           if (z == '\\' && p[2])
24             z = p[2];
25           z = Convert(z);
26           for(;;)
27             {
28               while (*s && Convert(*s) != z)
29                 s++;
30               if (!*s)
31                 return 0;
32               if (MATCH_FUNC_NAME(p+1, s))
33                 return 1;
34               s++;
35             }
36         }
37       else
38         {
39           if (*p == '\\' && p[1])
40             p++;
41           if (Convert(*p++) != Convert(*s++))
42             return 0;
43         }
44     }
45   return !*s;
46 }