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