summaryrefslogtreecommitdiff
path: root/src/wildcard.cpp
blob: 41070d14506c8f30fdae2f48902a09406760e4c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <string>
#include "inspircd_config.h"
#include "inspircd.h"

void Delete(char* str,int pos)
{
	char moo[MAXBUF];
	strcpy(moo,str);
	moo[pos] = '\0';
	strcpy(str,moo);
	strcat(str,moo+pos+1);
}

void Insert(char* substr,char* str,int pos)
{
	std::string a = str;
	a.insert(pos,substr);
	strcpy(str,a.c_str());
}


int MWC = 0;

bool match2(char* literal,char* mask)
{

char OldM[MAXBUF];
int I,I2;

if (MWC)
	return true;

if ((strstr(mask,"*")==0) && (strlen(literal) != strlen(mask)))
	return 0;
 I=0;
 I2=0;
 while (I < strlen(mask))
 {
   if (I2 >= strlen(literal))
	   return 0;
 
   if ((mask[I]=='*') && (MWC==0))
   {
     strcpy(OldM,mask);
     
     Delete(mask,I);
     
     while (strlen(mask)<255)
     {
       match2(literal,mask);
       if (MWC==2)
	       return 1;

       Insert("?",mask,I);
     }
     strcpy(mask,OldM);
     Delete(mask,I);
     Insert("?",mask,I);
   }
   if (mask[I]=='?')
   {
     I++;
     I2++;
     continue;
   }
   if (mask[I] != literal[I2])
	   return 0;
   if (MWC)
	   return 1;
   I++;
   I2++;
 }
 if (strlen(literal)==strlen(mask))
		 MWC=2;

}

bool match(char* literal, char* mask)
{
	char L[10240];
	char M[10240];
	MWC = 0;
	strncpy(L,literal,10240);
	strncpy(M,mask,10240);
	strlower(L);
	strlower(M);
	match2(L,M);
	return (MWC == 2);
}