wildmatch.c

ソースコードを見る。


関数

static int dowild (const uchar *p, const uchar *text, const uchar *const *a)
static int doliteral (const uchar *s, const uchar *text, const uchar *const *a)
static const uchar * trailing_N_elements (const uchar *const **a_ptr, int count)
int wildmatch (const char *pattern, const char *text)
int iwildmatch (const char *pattern, const char *text)
int wildmatch_array (const char *pattern, const char *const *texts, int where)
int litmatch_array (const char *string, const char *const *texts, int where)

変数

int wildmatch_iteration_count
static int force_lower_case = 0

関数

static int dowild ( const uchar *  p,
const uchar *  text,
const uchar *const *  a 
) [static]

wildmatch.c64 行で定義されています。

参照先 force_lower_casematched()wildmatch_iteration_count.

参照元 iwildmatch()wildmatch()wildmatch_array().

00065 {
00066     uchar p_ch;
00067 
00068 #ifdef WILD_TEST_ITERATIONS
00069     wildmatch_iteration_count++;
00070 #endif
00071 
00072     for ( ; (p_ch = *p) != '\0'; text++, p++) {
00073         int matched, special;
00074         uchar t_ch, prev_ch;
00075         while ((t_ch = *text) == '\0') {
00076             if (*a == NULL) {
00077                 if (p_ch != '*')
00078                     return ABORT_ALL;
00079                 break;
00080             }
00081             text = *a++;
00082         }
00083         if (force_lower_case && ISUPPER(t_ch))
00084             t_ch = tolower(t_ch);
00085         switch (p_ch) {
00086           case '\\':
00087             /* Literal match with following character.  Note that the test
00088              * in "default" handles the p[1] == '\0' failure case. */
00089             p_ch = *++p;
00090             /* FALLTHROUGH */
00091           default:
00092             if (t_ch != p_ch)
00093                 return FALSE;
00094             continue;
00095           case '?':
00096             /* Match anything but '/'. */
00097             if (t_ch == '/')
00098                 return FALSE;
00099             continue;
00100           case '*':
00101             if (*++p == '*') {
00102                 while (*++p == '*') {}
00103                 special = TRUE;
00104             } else
00105                 special = FALSE;
00106             if (*p == '\0') {
00107                 /* Trailing "**" matches everything.  Trailing "*" matches
00108                  * only if there are no more slash characters. */
00109                 if (!special) {
00110                     do {
00111                         if (strchr((char*)text, '/') != NULL)
00112                             return FALSE;
00113                     } while ((text = *a++) != NULL);
00114                 }
00115                 return TRUE;
00116             }
00117             while (1) {
00118                 if (t_ch == '\0') {
00119                     if ((text = *a++) == NULL)
00120                         break;
00121                     t_ch = *text;
00122                     continue;
00123                 }
00124                 if ((matched = dowild(p, text, a)) != FALSE) {
00125                     if (!special || matched != ABORT_TO_STARSTAR)
00126                         return matched;
00127                 } else if (!special && t_ch == '/')
00128                     return ABORT_TO_STARSTAR;
00129                 t_ch = *++text;
00130             }
00131             return ABORT_ALL;
00132           case '[':
00133             p_ch = *++p;
00134 #ifdef NEGATE_CLASS2
00135             if (p_ch == NEGATE_CLASS2)
00136                 p_ch = NEGATE_CLASS;
00137 #endif
00138             /* Assign literal TRUE/FALSE because of "matched" comparison. */
00139             special = p_ch == NEGATE_CLASS? TRUE : FALSE;
00140             if (special) {
00141                 /* Inverted character class. */
00142                 p_ch = *++p;
00143             }
00144             prev_ch = 0;
00145             matched = FALSE;
00146             do {
00147                 if (!p_ch)
00148                     return ABORT_ALL;
00149                 if (p_ch == '\\') {
00150                     p_ch = *++p;
00151                     if (!p_ch)
00152                         return ABORT_ALL;
00153                     if (t_ch == p_ch)
00154                         matched = TRUE;
00155                 } else if (p_ch == '-' && prev_ch && p[1] && p[1] != ']') {
00156                     p_ch = *++p;
00157                     if (p_ch == '\\') {
00158                         p_ch = *++p;
00159                         if (!p_ch)
00160                             return ABORT_ALL;
00161                     }
00162                     if (t_ch <= p_ch && t_ch >= prev_ch)
00163                         matched = TRUE;
00164                     p_ch = 0; /* This makes "prev_ch" get set to 0. */
00165                 } else if (p_ch == '[' && p[1] == ':') {
00166                     const uchar *s;
00167                     int i;
00168                     for (s = p += 2; (p_ch = *p) && p_ch != ']'; p++) {}
00169                     if (!p_ch)
00170                         return ABORT_ALL;
00171                     i = p - s - 1;
00172                     if (i < 0 || p[-1] != ':') {
00173                         /* Didn't find ":]", so treat like a normal set. */
00174                         p = s - 2;
00175                         p_ch = '[';
00176                         if (t_ch == p_ch)
00177                             matched = TRUE;
00178                         continue;
00179                     }
00180                     if (CC_EQ(s,i, "alnum")) {
00181                         if (ISALNUM(t_ch))
00182                             matched = TRUE;
00183                     } else if (CC_EQ(s,i, "alpha")) {
00184                         if (ISALPHA(t_ch))
00185                             matched = TRUE;
00186                     } else if (CC_EQ(s,i, "blank")) {
00187                         if (ISBLANK(t_ch))
00188                             matched = TRUE;
00189                     } else if (CC_EQ(s,i, "cntrl")) {
00190                         if (ISCNTRL(t_ch))
00191                             matched = TRUE;
00192                     } else if (CC_EQ(s,i, "digit")) {
00193                         if (ISDIGIT(t_ch))
00194                             matched = TRUE;
00195                     } else if (CC_EQ(s,i, "graph")) {
00196                         if (ISGRAPH(t_ch))
00197                             matched = TRUE;
00198                     } else if (CC_EQ(s,i, "lower")) {
00199                         if (ISLOWER(t_ch))
00200                             matched = TRUE;
00201                     } else if (CC_EQ(s,i, "print")) {
00202                         if (ISPRINT(t_ch))
00203                             matched = TRUE;
00204                     } else if (CC_EQ(s,i, "punct")) {
00205                         if (ISPUNCT(t_ch))
00206                             matched = TRUE;
00207                     } else if (CC_EQ(s,i, "space")) {
00208                         if (ISSPACE(t_ch))
00209                             matched = TRUE;
00210                     } else if (CC_EQ(s,i, "upper")) {
00211                         if (ISUPPER(t_ch))
00212                             matched = TRUE;
00213                     } else if (CC_EQ(s,i, "xdigit")) {
00214                         if (ISXDIGIT(t_ch))
00215                             matched = TRUE;
00216                     } else /* malformed [:class:] string */
00217                         return ABORT_ALL;
00218                     p_ch = 0; /* This makes "prev_ch" get set to 0. */
00219                 } else if (t_ch == p_ch)
00220                     matched = TRUE;
00221             } while (prev_ch = p_ch, (p_ch = *++p) != ']');
00222             if (matched == special || t_ch == '/')
00223                 return FALSE;
00224             continue;
00225         }
00226     }
00227 
00228     do {
00229         if (*text)
00230             return FALSE;
00231     } while ((text = *a++) != NULL);
00232 
00233     return TRUE;
00234 }

static int doliteral ( const uchar *  s,
const uchar *  text,
const uchar *const *  a 
) [static]

wildmatch.c238 行で定義されています。

参照元 litmatch_array().

00239 {
00240     for ( ; *s != '\0'; text++, s++) {
00241         while (*text == '\0') {
00242             if ((text = *a++) == NULL)
00243                 return FALSE;
00244         }
00245         if (*text != *s)
00246             return FALSE;
00247     }
00248 
00249     do {
00250         if (*text)
00251             return FALSE;
00252     } while ((text = *a++) != NULL);
00253 
00254     return TRUE;
00255 }

static const uchar* trailing_N_elements ( const uchar *const **  a_ptr,
int  count 
) [static]

wildmatch.c260 行で定義されています。

参照元 litmatch_array()wildmatch_array().

00261 {
00262     const uchar*const *a = *a_ptr;
00263     const uchar*const *first_a = a;
00264 
00265     while (*a)
00266             a++;
00267 
00268     while (a != first_a) {
00269         const uchar *s = *--a;
00270         s += strlen((char*)s);
00271         while (--s >= *a) {
00272             if (*s == '/' && !--count) {
00273                 *a_ptr = a+1;
00274                 return s+1;
00275             }
00276         }
00277     }
00278 
00279     if (count == 1) {
00280         *a_ptr = a+1;
00281         return *a;
00282     }
00283 
00284     return NULL;
00285 }

int wildmatch ( const char *  pattern,
const char *  text 
)

wildmatch.c288 行で定義されています。

参照先 dowild()wildmatch_iteration_count.

参照元 auth_server()match_hostname()run_test()set_refuse_options().

00289 {
00290     static const uchar *nomore[1]; /* A NULL pointer. */
00291 #ifdef WILD_TEST_ITERATIONS
00292     wildmatch_iteration_count = 0;
00293 #endif
00294     return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
00295 }

int iwildmatch ( const char *  pattern,
const char *  text 
)

wildmatch.c298 行で定義されています。

参照先 dowild()force_lower_casewildmatch_iteration_count.

参照元 set_compression().

00299 {
00300     static const uchar *nomore[1]; /* A NULL pointer. */
00301     int ret;
00302 #ifdef WILD_TEST_ITERATIONS
00303     wildmatch_iteration_count = 0;
00304 #endif
00305     force_lower_case = 1;
00306     ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
00307     force_lower_case = 0;
00308     return ret;
00309 }

int wildmatch_array ( const char *  pattern,
const char *const *  texts,
int  where 
)

wildmatch.c316 行で定義されています。

参照先 dowild()trailing_N_elements()wildmatch_iteration_count.

参照元 rule_matches()run_test().

00317 {
00318     const uchar *p = (const uchar*)pattern;
00319     const uchar*const *a = (const uchar*const*)texts;
00320     const uchar *text;
00321     int matched;
00322 
00323 #ifdef WILD_TEST_ITERATIONS
00324     wildmatch_iteration_count = 0;
00325 #endif
00326 
00327     if (where > 0)
00328         text = trailing_N_elements(&a, where);
00329     else
00330         text = *a++;
00331     if (!text)
00332         return FALSE;
00333 
00334     if ((matched = dowild(p, text, a)) != TRUE && where < 0
00335      && matched != ABORT_ALL) {
00336         while (1) {
00337             if (*text == '\0') {
00338                 if ((text = (uchar*)*a++) == NULL)
00339                     return FALSE;
00340                 continue;
00341             }
00342             if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE
00343              && matched != ABORT_TO_STARSTAR)
00344                 break;
00345         }
00346     }
00347     return matched == TRUE;
00348 }

int litmatch_array ( const char *  string,
const char *const *  texts,
int  where 
)

wildmatch.c354 行で定義されています。

参照先 doliteral()trailing_N_elements().

参照元 rule_matches().

00355 {
00356     const uchar *s = (const uchar*)string;
00357     const uchar*const *a = (const uchar* const*)texts;
00358     const uchar *text;
00359 
00360     if (where > 0)
00361         text = trailing_N_elements(&a, where);
00362     else
00363         text = *a++;
00364     if (!text)
00365         return FALSE;
00366 
00367     return doliteral(s, text, a) == TRUE;
00368 }


変数

int wildmatch_iteration_count

wildmatch.c57 行で定義されています。

参照元 dowild()iwildmatch()run_test()wildmatch()wildmatch_array().

int force_lower_case = 0 [static]

wildmatch.c60 行で定義されています。

参照元 dowild()iwildmatch().


rsyncに対してSat Dec 5 19:45:46 2009に生成されました。  doxygen 1.4.7