]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/wildcard.cpp
Fixed 'make clean'
[user/henk/code/inspircd.git] / src / wildcard.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <string>
18 #include "inspircd_config.h"
19 #include "inspircd.h"
20 #include "inspstring.h"
21
22 // Wed 27 Apr 2005 - Brain
23 // I've taken our our old wildcard routine -
24 // although comprehensive, it was topheavy and very
25 // slow, and ate masses of cpu when doing lots of
26 // comparisons. This is the 'de-facto' routine used
27 // by many, nobody really knows who wrote it first
28 // or what license its under, i've seen examples of it
29 // (unattributed to any author) all over the 'net.
30 // For now, we'll just consider this public domain.
31
32 int wildcmp(char *wild, char *string)
33 {
34         char *cp, *mp;
35         while ((*string) && (*wild != '*'))
36         {
37                 if ((*wild != *string) && (*wild != '?'))
38                 {
39                         return 0;
40                 }
41                 wild++;
42                 string++;
43         }
44
45         while (*string)
46         {
47                 if (*wild == '*')
48                 {
49                         if (!*++wild)
50                         {
51                                 return 1;
52                         }
53                         mp = wild;
54                         cp = string+1;
55                 }
56                 else
57                 if ((*wild == *string) || (*wild == '?'))
58                 {
59                         wild++;
60                         string++;
61                 }
62                 else
63                 {
64                         wild = mp;
65                         string = cp++;
66                 }
67
68         }
69
70         while (*wild == '*')
71         {
72                 wild++;
73         }
74
75         return !*wild;
76 }
77
78 // This wrapper function is required to convert both
79 // strings to 'scandanavian lowercase' and make copies
80 // of them to a safe location. It also ensures we don't
81 // bite off more than we can chew with the length of
82 // the string.
83
84 bool match(const char* literal, const char* mask)
85 {
86         static char L[10240];
87         static char M[10240];
88         strlcpy(L,literal,10240);
89         strlcpy(M,mask,10240);
90         strlower(L);
91         strlower(M);
92         return wildcmp(M,L);
93 }