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