Back to index

php5  5.3.10
Defines | Functions
fnmatch.h File Reference
#include "php.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define FNM_NOMATCH   1 /* Match failed. */
#define FNM_NOESCAPE   0x01 /* Disable backslash escaping. */
#define FNM_PATHNAME   0x02 /* Slash must be matched by slash. */
#define FNM_PERIOD   0x04 /* Period must be matched by period. */
#define FNM_LEADING_DIR   0x08 /* Ignore /<tail> after Imatch. */
#define FNM_CASEFOLD   0x10 /* Case insensitive search. */
#define FNM_PREFIX_DIRS   0x20 /* Directory prefixes of pattern match too. */

Functions

PHPAPI int fnmatch (const char *pattern, const char *string, int flags)

Define Documentation

#define FNM_CASEFOLD   0x10 /* Case insensitive search. */

Definition at line 49 of file fnmatch.h.

#define FNM_LEADING_DIR   0x08 /* Ignore /<tail> after Imatch. */

Definition at line 48 of file fnmatch.h.

#define FNM_NOESCAPE   0x01 /* Disable backslash escaping. */

Definition at line 45 of file fnmatch.h.

#define FNM_NOMATCH   1 /* Match failed. */

Definition at line 43 of file fnmatch.h.

#define FNM_PATHNAME   0x02 /* Slash must be matched by slash. */

Definition at line 46 of file fnmatch.h.

#define FNM_PERIOD   0x04 /* Period must be matched by period. */

Definition at line 47 of file fnmatch.h.

#define FNM_PREFIX_DIRS   0x20 /* Directory prefixes of pattern match too. */

Definition at line 50 of file fnmatch.h.


Function Documentation

PHPAPI int fnmatch ( const char *  pattern,
const char *  string,
int  flags 
)

Definition at line 59 of file fnmatch.c.

{
       const char *stringstart;
       char c, test;

       for (stringstart = string;;)
              switch (c = *pattern++) {
              case EOS:
                     if ((flags & FNM_LEADING_DIR) && *string == '/')
                            return (0);
                     return (*string == EOS ? 0 : FNM_NOMATCH);
              case '?':
                     if (*string == EOS)
                            return (FNM_NOMATCH);
                     if (*string == '/' && (flags & FNM_PATHNAME))
                            return (FNM_NOMATCH);
                     if (*string == '.' && (flags & FNM_PERIOD) &&
                         (string == stringstart ||
                         ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
                            return (FNM_NOMATCH);
                     ++string;
                     break;
              case '*':
                     c = *pattern;
                     /* Collapse multiple stars. */
                     while (c == '*')
                            c = *++pattern;

                     if (*string == '.' && (flags & FNM_PERIOD) &&
                         (string == stringstart ||
                         ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
                            return (FNM_NOMATCH);

                     /* Optimize for pattern with * at end or before /. */
                     if (c == EOS)
                            if (flags & FNM_PATHNAME)
                                   return ((flags & FNM_LEADING_DIR) ||
                                       strchr(string, '/') == NULL ?
                                       0 : FNM_NOMATCH);
                            else
                                   return (0);
                     else if (c == '/' && flags & FNM_PATHNAME) {
                            if ((string = strchr(string, '/')) == NULL)
                                   return (FNM_NOMATCH);
                            break;
                     }

                     /* General case, use recursion. */
                     while ((test = *string) != EOS) {
                            if (!fnmatch(pattern, string, flags & ~FNM_PERIOD))
                                   return (0);
                            if (test == '/' && flags & FNM_PATHNAME)
                                   break;
                            ++string;
                     }
                     return (FNM_NOMATCH);
              case '[':
                     if (*string == EOS)
                            return (FNM_NOMATCH);
                     if (*string == '/' && flags & FNM_PATHNAME)
                            return (FNM_NOMATCH);
                     if ((pattern =
                         rangematch(pattern, *string, flags)) == NULL)
                            return (FNM_NOMATCH);
                     ++string;
                     break;
              case '\\':
                     if (!(flags & FNM_NOESCAPE)) {
                            if ((c = *pattern++) == EOS) {
                                   c = '\\';
                                   --pattern;
                            }
                     }
                     /* FALLTHROUGH */
              default:
                     if (c == *string)
                            ;
                     else if ((flags & FNM_CASEFOLD) &&
                             (tolower((unsigned char)c) ==
                              tolower((unsigned char)*string)))
                            ;
                     else if ((flags & FNM_PREFIX_DIRS) && *string == EOS &&
                          (c == '/' && string != stringstart ||
                          string == stringstart+1 && *stringstart == '/') )
                            return (0);
                     else
                            return (FNM_NOMATCH);
                     string++;
                     break;
              }
       /* NOTREACHED */
}

Here is the call graph for this function:

Here is the caller graph for this function: