]> mj.ucw.cz Git - libucw.git/blob - lib/ctmatch.c
bugfixes
[libucw.git] / lib / ctmatch.c
1 /*
2  *      UCW Library -- Content-Type Pattern Matching
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 "lib/lib.h"
11 #include "lib/chartype.h"
12
13 int
14 match_ct_patt(byte *p, byte *t)
15 {
16   if (*p == '*' && !p[1])               /* "*" matches everything */
17     return 1;
18
19   if (*p == '*' && p[1] == '/')         /* "*" on the left-hand side */
20     {
21       while (*t && *t != ' ' && *t != ';' && *t != '/')
22         t++;
23       p += 2;
24     }
25   else                                  /* Normal left-hand side */
26     {
27       while (*p != '/')
28         if (Cupcase(*p++) != Cupcase(*t++))
29           return 0;
30       p++;
31     }
32   if (*t++ != '/')
33     return 0;
34
35   if (*p == '*' && !p[1])               /* "*" on the right-hand side */
36     return 1;
37   while (*p)
38     if (Cupcase(*p++) != Cupcase(*t++))
39       return 0;
40   if (*t && *t != ' ' && *t != ';')
41     return 0;
42
43   return 1;
44 }