]> mj.ucw.cz Git - libucw.git/blob - lib/ctmatch.c
If have GET_O and GET_P, we should have PUT_O and PUT_P as well.
[libucw.git] / lib / ctmatch.c
1 /*
2  *      Sherlock Library -- Content-Type Pattern Matching
3  *
4  *      (c) 1997 Martin Mares <mj@ucw.cz>
5  */
6
7 #include "lib/lib.h"
8 #include "lib/chartype.h"
9
10 int
11 match_ct_patt(byte *p, byte *t)
12 {
13   if (*p == '*' && !p[1])               /* "*" matches everything */
14     return 1;
15
16   if (*p == '*' && p[1] == '/')         /* "*" on the left-hand side */
17     {
18       while (*t && *t != ' ' && *t != ';' && *t != '/')
19         t++;
20       p += 2;
21     }
22   else                                  /* Normal left-hand side */
23     {
24       while (*p != '/')
25         if (Cupcase(*p++) != Cupcase(*t++))
26           return 0;
27       p++;
28     }
29   if (*t++ != '/')
30     return 0;
31
32   if (*p == '*' && !p[1])               /* "*" on the right-hand side */
33     return 1;
34   while (*p)
35     if (Cupcase(*p++) != Cupcase(*t++))
36       return 0;
37   if (*t && *t != ' ' && *t != ';')
38     return 0;
39
40   return 1;
41 }