]> mj.ucw.cz Git - libucw.git/blob - lib/patmatch.h
2aaef12be0fb811b23f310698812a5761438e2d8
[libucw.git] / lib / patmatch.h
1 /*
2  *      Sherlock Library -- Generic Shell-Like Pattern Matching (currently only '?' and '*')
3  *
4  *      (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 int
8 MATCH_FUNC_NAME(byte *p, byte *s)
9 {
10   while (*p)
11     {
12       if (*p == '?' && *s)
13         p++, s++;
14       else if (*p == '*')
15         {
16           int z = p[1];
17
18           if (!z)
19             return 1;
20           if (z == '\\' && p[2])
21             z = p[2];
22           z = Convert(z);
23           for(;;)
24             {
25               while (*s && Convert(*s) != z)
26                 s++;
27               if (!*s)
28                 return 0;
29               if (MATCH_FUNC_NAME(p+1, s))
30                 return 1;
31               s++;
32             }
33         }
34       else
35         {
36           if (*p == '\\' && p[1])
37             p++;
38           if (Convert(*p++) != Convert(*s++))
39             return 0;
40         }
41     }
42   return !*s;
43 }