-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwildmat.c
66 lines (63 loc) · 1.58 KB
/
wildmat.c
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
#include "wildmat.h"
/* Taken from spamcontrol patch.
*
* Author:
* Dr. Erwin Hoffmann - FEHCom Germany
* E-Mail: [email protected]
*
*/
int
DoMatch(char *text, char *p, int plen)
{
register int last;
register int matched;
register int reverse;
register char * savep = p;
register char * savet = text;
for ( ; *p && (p - savep) < plen; text++, p++) {
if (*text == '\0' && *p != '*')
return ABORT;
switch (*p) {
case '\\':
/* Literal match with following character. */
p++;
/* FALLTHROUGH */
default:
if (*text != *p)
return FALSE;
continue;
case '?':
/* Match anything. */
continue;
case '*':
while (*++p == '*' && (p - savep) < plen)
/* Consecutive stars act just like one. */
continue;
if (*p == '\0')
/* Trailing star matches everything. */
return TRUE;
while (*text)
if ((matched = DoMatch(text++, p, (plen - (p - savep)))) != FALSE)
return matched;
return ABORT;
case '[':
reverse = p[1] == NEGATE_CLASS ? TRUE : FALSE;
if (reverse)
/* Inverted character class. */
p++;
matched = FALSE;
if (p[1] == ']' || p[1] == '-')
if (*++p == *text)
matched = TRUE;
for (last = *p; *++p && *p != ']' && (p - savep) < plen; last = *p)
/* This next line requires a good C compiler. */
if (*p == '-' && p[1] != ']'
? *text <= *++p && *text >= last : *text == *p)
matched = TRUE;
if (matched == reverse)
return FALSE;
continue;
}
}
return *text == '\0';
}