예제 #1
0
파일: hha.c 프로젝트: C4-sic/codetastrophe
static void HHA_enumerateFiles(dvoid *opaque, const char *dname,
                               int omitSymLinks, PHYSFS_EnumFilesCallback cb,
                               const char *origdir, void *callbackdata)
{
    size_t dlen = strlen(dname),
           dlen_inc = dlen + ((dlen > 0) ? 1 : 0);
    HHAinfo *info = (HHAinfo *) opaque;
    HHAentry *entry = info->entries;
    HHAentry *lastEntry = &info->entries[info->entryCount];
    char lastDir[256];
    lastDir[0] = '\0';
    
    if (dlen)
    {
        while (entry < lastEntry)
        {
            if (!strncmp(dname, entry->dir, dlen))
                break;
            entry++;
        }
    }
    
    
    while (entry < lastEntry)
    {
        if(!strcmp(dname, entry->dir))
            doEnumCallback(cb, callbackdata, origdir, entry->name, strlen(entry->name));
        
        if(strlen(entry->dir) > dlen)
        {
            char *fname = entry->dir + dlen_inc;
            char *dirNameEnd = strchr(fname, '/');
            size_t dirNameLen = dirNameEnd - fname;
            if (dirNameEnd == NULL)
                dirNameLen = strlen(fname);
            if (dlen && strncmp(dname, entry->dir, dlen))
                break;
            if (strncmp(lastDir, fname, dirNameLen))
            {
                doEnumCallback(cb, callbackdata, origdir, fname, dirNameLen);
                strncpy(lastDir, fname, dirNameLen);
                lastDir[dirNameLen] = '\0';
            }
        }
        entry++;
    }

} /* HHA_enumerateFiles */
예제 #2
0
void UNPK_enumerateFiles(PHYSFS_Dir *opaque, const char *dname,
                         int omitSymLinks, PHYSFS_EnumFilesCallback cb,
                         const char *origdir, void *callbackdata)
{
    UNPKinfo *info = ((UNPKinfo *) opaque);
    PHYSFS_sint32 dlen, dlen_inc, max, i;

    i = findStartOfDir(info, dname, 0);
    if (i == -1)  /* no such directory. */
        return;

    dlen = (PHYSFS_sint32) strlen(dname);
    if ((dlen > 0) && (dname[dlen - 1] == '/')) /* ignore trailing slash. */
        dlen--;

    dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
    max = (PHYSFS_sint32) info->entryCount;
    while (i < max)
    {
        char *add;
        char *ptr;
        PHYSFS_sint32 ln;
        char *e = info->entries[i].name;
        if ((dlen) &&
            ((__PHYSFS_strnicmpASCII(e, dname, dlen)) || (e[dlen] != '/')))
        {
            break;  /* past end of this dir; we're done. */
        } /* if */

        add = e + dlen_inc;
        ptr = strchr(add, '/');
        ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
        doEnumCallback(cb, callbackdata, origdir, add, ln);
        ln += dlen_inc;  /* point past entry to children... */

        /* increment counter and skip children of subdirs... */
        while ((++i < max) && (ptr != NULL))
        {
            char *e_new = info->entries[i].name;
            if ((__PHYSFS_strnicmpASCII(e, e_new, ln) != 0) ||
                (e_new[ln] != '/'))
            {
                break;
            } /* if */
        } /* while */
    } /* while */
} /* UNPK_enumerateFiles */
예제 #3
0
static void LZMA_enumerateFiles(dvoid *opaque, const char *dname,
                                int omitSymLinks, PHYSFS_EnumFilesCallback cb,
                                const char *origdir, void *callbackdata)
{
    LZMAarchive *archive = (LZMAarchive *) opaque;
    PHYSFS_sint32 dlen;
    PHYSFS_sint32 dlen_inc;
    PHYSFS_sint32 max;
    PHYSFS_sint32 i;

    i = lzma_find_start_of_dir(archive, dname, 0);
    if (i == -1)  /* no such directory. */
        return;

    dlen = strlen(dname);
    if ((dlen > 0) && (dname[dlen - 1] == '/')) /* ignore trailing slash. */
        dlen--;

    dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
    max = (PHYSFS_sint32) archive->db.Database.NumFiles;
    while (i < max)
    {
        char *add;
        char *ptr;
        PHYSFS_sint32 ln;
        char *e = archive->db.Database.Files[i].Name;
        if ((dlen) && ((strncmp(e, dname, dlen)) || (e[dlen] != '/')))
            break;  /* past end of this dir; we're done. */

        add = e + dlen_inc;
        ptr = strchr(add, '/');
        ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
        doEnumCallback(cb, callbackdata, origdir, add, ln);
        ln += dlen_inc;  /* point past entry to children... */

        /* increment counter and skip children of subdirs... */
        while ((++i < max) && (ptr != NULL))
        {
            char *e_new = archive->db.Database.Files[i].Name;
            if ((strncmp(e, e_new, ln) != 0) || (e_new[ln] != '/'))
                break;
        } /* while */
    } /* while */
} /* LZMA_enumerateFiles */
예제 #4
0
static void LZMA_enumerateFiles(void *opaque, const char *dname,
                                PHYSFS_EnumFilesCallback cb,
                                const char *origdir, void *callbackdata)
{
    size_t dlen = strlen(dname),
           dlen_inc = dlen + ((dlen > 0) ? 1 : 0);
    LZMAarchive *archive = (LZMAarchive *) opaque;
    LZMAfile *file = NULL,
            *lastFile = &archive->files[archive->db.Database.NumFiles];
        if (dlen)
        {
            file = lzma_find_file(archive, dname);
            if (file != NULL) /* if 'file' is NULL it should stay so, otherwise errors will not be handled */
                file += 1;
        }
        else
        {
            file = archive->files;
        }

    BAIL_IF_MACRO(file == NULL, PHYSFS_ERR_NOT_FOUND, );

    while (file < lastFile)
    {
        const char * fname = file->item->Name;
        const char * dirNameEnd = fname + dlen_inc;

        if (strncmp(dname, fname, dlen) != 0) /* Stop after mismatch, archive->files is sorted */
            break;

        if (strchr(dirNameEnd, '/')) /* Skip subdirs */
        {
            file++;
            continue;
        }

        /* Do the actual callback... */
        doEnumCallback(cb, callbackdata, origdir, dirNameEnd, strlen(dirNameEnd));

        file++;
    }
} /* LZMA_enumerateFiles */