]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/wildcard.cpp
STL namespace fixes
[user/henk/code/inspircd.git] / src / wildcard.cpp
1 #include <string>
2 #include "inspircd_config.h"
3 #include "inspircd.h"
4
5 void Delete(char* str,int pos)
6 {
7         char moo[MAXBUF];
8         strcpy(moo,str);
9         moo[pos] = '\0';
10         strcpy(str,moo);
11         strcat(str,moo+pos+1);
12 }
13
14 void Insert(char* substr,char* str,int pos)
15 {
16         std::string a = str;
17         a.insert(pos,substr);
18         strcpy(str,a.c_str());
19 }
20
21
22 int MWC = 0;
23
24 bool match2(char* literal,char* mask)
25 {
26
27 char OldM[MAXBUF];
28 int I,I2;
29
30 if (MWC)
31         return true;
32
33 if ((strstr(mask,"*")==0) && (strlen(literal) != strlen(mask)))
34         return 0;
35  I=0;
36  I2=0;
37  while (I < strlen(mask))
38  {
39    if (I2 >= strlen(literal))
40            return 0;
41  
42    if ((mask[I]=='*') && (MWC==0))
43    {
44      strcpy(OldM,mask);
45      
46      Delete(mask,I);
47      
48      while (strlen(mask)<255)
49      {
50        match2(literal,mask);
51        if (MWC==2)
52                return 1;
53
54        Insert("?",mask,I);
55      }
56      strcpy(mask,OldM);
57      Delete(mask,I);
58      Insert("?",mask,I);
59    }
60    if (mask[I]=='?')
61    {
62      I++;
63      I2++;
64      continue;
65    }
66    if (mask[I] != literal[I2])
67            return 0;
68    if (MWC)
69            return 1;
70    I++;
71    I2++;
72  }
73  if (strlen(literal)==strlen(mask))
74                  MWC=2;
75
76 }
77
78 bool match(char* literal, char* mask)
79 {
80         char L[10240];
81         char M[10240];
82         MWC = 0;
83         strncpy(L,literal,10240);
84         strncpy(M,mask,10240);
85         strlower(L);
86         strlower(M);
87         match2(L,M);
88         return (MWC == 2);
89 }
90