11#include "wildcards.hpp"
13int Wildcard::wildcardfit(
const char* wildcard,
const char* test) {
16 for (; (
'\000' != *wildcard) && (1 == fit) && (
'\000' != *test); wildcard++) {
20 fit = set(&wildcard, &test);
28 fit = asterisk(&wildcard, &test);
34 fit = (int)(*wildcard == *test);
38 while ((*wildcard ==
'*') && (1 == fit))
42 return (
int)((1 == fit) && (
'\0' == *test) && (
'\0' == *wildcard));
45int Wildcard::set(
const char** wildcard,
const char** test) {
50 if (
'!' == **wildcard) {
54 while ((
']' != **wildcard) || (1 == at_beginning)) {
56 if ((
'-' == **wildcard) && ((*(*wildcard - 1)) < (*(*wildcard + 1))) &&
57 (
']' != *(*wildcard + 1)) && (0 == at_beginning)) {
58 if (((**test) >= (*(*wildcard - 1))) &&
59 ((**test) <= (*(*wildcard + 1)))) {
63 }
else if ((**wildcard) == (**test)) {
72 if (1 == fit) (*test)++;
77int Wildcard::asterisk(
const char** wildcard,
const char** test) {
83 while ((
'\000' != (**test)) && ((
'?' == **wildcard) || (
'*' == **wildcard))) {
84 if (
'?' == **wildcard) (*test)++;
89 while (
'*' == (**wildcard))
92 if ((
'\0' == (**test)) && (
'\0' != (**wildcard)))
return (fit = 0);
93 if ((
'\0' == (**test)) && (
'\0' == (**wildcard)))
98 if (0 == wildcardfit(*wildcard, (*test))) {
103 while (((**wildcard) != (**test)) && (
'[' != (**wildcard)) &&
106 }
while (((
'\0' != **test)) ? (0 == wildcardfit(*wildcard, (*test))) :
109 if ((
'\0' == **test) && (
'\0' == **wildcard)) fit = 1;