00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef lint
00021 static const char rcsid[] = "$Id: match.c,v 1.6 2004-10-17 05:14:06 stdarg Exp $";
00022 #endif
00023
00024 #include <eggdrop/eggdrop.h>
00025
00026 #define irctoupper toupper
00027
00028
00029 int wild_match_per(const char *wild, const char *matchtext) {
00030 const char *fallback=0;
00031 int match = 0, saved = 0, count = 0, wildcard = 0;
00032
00033
00034 if (!matchtext || !wild)
00035 return 0;
00036
00037 while(*matchtext && *wild) {
00038 switch (*wild) {
00039 case WILDP :
00040 fallback = wild++;
00041 match = 1;
00042 while((*(wild++)==WILDP));
00043 if (*wild==QUOTE)
00044 wild++;
00045 while(*matchtext && (irctoupper(*wild) != irctoupper(*matchtext)))
00046 if (*matchtext==' ') {
00047 match=0;
00048 break;
00049 } else
00050 matchtext++;
00051 break;
00052 case WILDQ :
00053 wild++;
00054 matchtext++;
00055 break;
00056 case WILDT :
00057 wild++;
00058 if (*matchtext!=' '){
00059 count = saved;
00060 if (!fallback)
00061 return 0;
00062 wild = fallback-1;
00063 break;
00064 }
00065 while ((*(matchtext++)==' '));
00066 count++;
00067 break;
00068 case WILDS :
00069 if (!*++wild)
00070 return (count+saved+1);
00071 wildcard = 1;
00072 break;
00073 default :
00074 if (*wild==QUOTE)
00075 wild++;
00076 if (wildcard) {
00077 saved = count;
00078 match = count = 0;
00079 fallback = wild;
00080 while(*matchtext && (irctoupper(*wild) != irctoupper(*matchtext)))
00081 matchtext++;
00082 if (!*matchtext) {
00083 match=1;
00084 break;
00085 }
00086 }
00087 if (irctoupper(*wild) != irctoupper(*matchtext)) {
00088 if (!fallback)
00089 return 0;
00090 count = saved;
00091 wild = fallback-1;
00092 break;
00093 }
00094 count++;
00095 wildcard = 0;
00096 match=1;
00097 if (*wild)
00098 wild++;
00099 if (*matchtext)
00100 matchtext++;
00101 }
00102 }
00103 return (!match || *wild || *matchtext)?0:(count+saved+1);
00104 }
00105
00106
00107 int wild_match(const char *wild, const char *matchtext) {
00108 const char *fallback=0;
00109 int match = 0, count = 0, saved = 0, wildcard = 0;
00110
00111
00112 if (!matchtext || !wild)
00113 return 0;
00114
00115 while(*matchtext && *wild) {
00116 switch (*wild) {
00117 case WILDQ :
00118 wild++;
00119 matchtext++;
00120 break;
00121 while ((*(matchtext++)==' '));
00122 break;
00123 case WILDS :
00124 if (!*++wild)
00125 return (count+saved+1);
00126 wildcard = 1;
00127 break;
00128 default :
00129 if (*wild==QUOTE)
00130 wild++;
00131 if (wildcard) {
00132 saved = count;
00133 match = count = 0;
00134 fallback = wild;
00135 while(*matchtext && (irctoupper(*wild) != irctoupper(*matchtext)))
00136 matchtext++;
00137 if (!*matchtext) {
00138 match=1;
00139 break;
00140 }
00141 }
00142 if (irctoupper(*wild) != irctoupper(*matchtext)) {
00143 if (!fallback)
00144 return 0;
00145 count = saved;
00146 wild = fallback-1;
00147 break;
00148 }
00149 wildcard = 0;
00150 count++;
00151 match=1;
00152 if (*wild)
00153 wild++;
00154 if (*matchtext)
00155 matchtext++;
00156 }
00157 }
00158 while (*wild && *wild == '*')
00159 wild++;
00160
00161 return (!match || *wild || *matchtext)?0:(count+saved+1);
00162 }