예제 #1
0
bool
TrackerString::Matches(const char* string, bool caseSensitivity,
	TrackerStringExpressionType expressionType) const
{
	switch (expressionType) {
		default:
		case kNone:
			return false;

		case kStartsWith:
			return StartsWith(string, caseSensitivity);

		case kEndsWith:
			return EndsWith(string, caseSensitivity);

		case kContains:
			return Contains(string, caseSensitivity);

		case kGlobMatch:
			return MatchesGlob(string, caseSensitivity);

		case kRegexpMatch:
			return MatchesRegExp(string, caseSensitivity);
	}
}
예제 #2
0
static boolean MatchesAnyGlob(const char *name, glob_t *glob)
{
    int i;

    for (i = 0; i < glob->num_globs; ++i)
    {
        if (MatchesGlob(name, glob->globs[i], glob->flags))
        {
            return true;
        }
    }
    return false;
}
예제 #3
0
static boolean MatchesGlob(const char *name, const char *glob, int flags)
{
    int n, g;

    while (*glob != '\0')
    {
        n = *name;
        g = *glob;

        if ((flags & GLOB_FLAG_NOCASE) != 0)
        {
            n = tolower(n);
            g = tolower(g);
        }

        if (g == '*')
        {
            // To handle *-matching we skip past the * and recurse
            // to check each subsequent character in turn. If none
            // match then the whole match is a failure.
            while (*name != '\0')
            {
                if (MatchesGlob(name, glob + 1, flags))
                {
                    return true;
                }
                ++name;
            }
            return glob[1] == '\0';
        }
        else if (g != '?' && n != g)
        {
            // For normal characters the name must match the glob,
            // but for ? we don't care what the character is.
            return false;
        }

        ++name;
        ++glob;
    }

    // Match successful when glob and name end at the same time.
    return *name == '\0';
}
예제 #4
0
파일: file.c 프로젝트: cjd8363/Global-Illum
int ListDirectory(ClientData nulldata, Tcl_Interp *interp, int argc,
		  char **argv)
{
    struct dirent *dp;
    struct stat stbuf;
    char command[256];
    char fileName[MAX_FILES][MAX_NAME_LEN];
    boolean dirList[MAX_FILES];
    int permute[MAX_FILES];
    int	fileCount = 0;
    register int index;
    char fullName[MAXPATHLEN];
    char    *restPtr;

    sprintf(command, "ShowCurrentDirectory %s", currentPath);
    Tcl_Eval(interp, command, 0, (char **) NULL);

    if ( dfd == NULL )
    {
	fprintf(stderr, "TRIED TO LIST NULL DIRECTORY\n");

	return TCL_OK;
    }

/* check if root directory */
    if ( strlen(currentPath) != 1 )
    {
	sprintf(fileName[fileCount], "../");
	dirList[fileCount] = TRUE;
	fileCount++;
    }

    strcpy(fullName, currentPath);
    restPtr = &fullName[strlen(fullName)];

    while ( (dp = readdir(dfd)) != NULL )
    {
	strcpy(restPtr, dp->d_name);
	stat(fullName, &stbuf);

	if ( dp->d_name[0] != '.' )
	{
	    if ( S_ISDIR(stbuf.st_mode) )
	    {
		sprintf(fileName[fileCount], "%s/", dp->d_name);
		dirList[fileCount] = TRUE;
		fileCount++;
	    }
	    else
	    {
		if ( MatchesGlob(dp->d_name, globString) )
		{
		    strcpy(fileName[fileCount], dp->d_name);
		    dirList[fileCount] = FALSE;
		    fileCount++;
		}
	    }
	}
    }

    SortFiles(fileCount, fileName, dirList, permute);

    for ( index = 0; index < fileCount; index++ )
    {
	sprintf(command, "AddBrowseFile %s", fileName[permute[index]]);
	Tcl_Eval(interp, command, 0, (char **) NULL);
    }

    closedir(dfd);

    return TCL_OK;
}