archivers/zip.c
changeset 376 1e71c1ca196b
parent 372 2f438fcb9a94
child 379 d0c4ae4a302f
equal deleted inserted replaced
375:997d1172b370 376:1e71c1ca196b
  1251 
  1251 
  1252 static LinkedStringList *ZIP_enumerateFiles(DirHandle *h,
  1252 static LinkedStringList *ZIP_enumerateFiles(DirHandle *h,
  1253                                             const char *dirname,
  1253                                             const char *dirname,
  1254                                             int omitSymLinks)
  1254                                             int omitSymLinks)
  1255 {
  1255 {
       
  1256 #if 1
       
  1257     return(NULL);  /* !!! FIXME */
       
  1258 #else
  1256     ZIPinfo *info = ((ZIPinfo *) h->opaque);
  1259     ZIPinfo *info = ((ZIPinfo *) h->opaque);
  1257     PHYSFS_sint32 i, max = (PHYSFS_sint32) info->entryCount;
  1260     PHYSFS_sint32 i, tmp, max;
  1258     LinkedStringList *retval = NULL, *p = NULL;
  1261     LinkedStringList *retval = NULL, *p = NULL;
  1259     PHYSFS_uint32 dlen = strlen(dirname);
  1262     PHYSFS_uint32 dlen = strlen(dirname);
  1260 
  1263 
  1261     if ((dlen > 0) && (dirname[dlen - 1] == '/'))
  1264     if ((dlen > 0) && (dirname[dlen - 1] == '/'))
  1262         dlen--;
  1265         dlen--;
  1263 
  1266 
  1264     i = zip_find_start_of_dir(info, dirname, 0);
  1267     i = zip_find_start_of_dir(info, dirname, 0);
  1265     BAIL_IF_MACRO(i == -1, ERR_NO_SUCH_FILE, NULL);
  1268     BAIL_IF_MACRO(i == -1, ERR_NO_SUCH_FILE, NULL);
  1266 
  1269 
  1267     while (1)
  1270     for (max = (PHYSFS_sint32) info->entryCount; i < max; i++)
  1268     {
  1271     {
  1269         ZIPentry *entry = &info->entries[i];
  1272         ZIPentry *entry = &info->entries[i];
  1270         const char *add_file;
  1273         const char *add_file;
  1271         size_t strsize;
  1274         size_t strsize;
  1272         char *slash;
  1275         char *slash;
  1273 
  1276 
       
  1277         if ((dlen > 0) && (strncmp(entry->name, dirname, dlen) != 0))
       
  1278             break; /* we're past this dir's entries. */
       
  1279 
  1274         add_file = entry->name + dlen + ((dlen > 0) ? 1 : 0);
  1280         add_file = entry->name + dlen + ((dlen > 0) ? 1 : 0);
  1275         if ( ((omitSymLinks) && (zip_entry_is_symlink(entry))) ||
  1281         if ( ((omitSymLinks) && (zip_entry_is_symlink(entry))) ||
  1276              (*add_file == '\0') ) /* skip links and the dir entry itself. */
  1282              (*add_file == '\0') ) /* skip links and the dir entry itself. */
  1277         {
  1283         {
  1278             if (++i >= max) break; else continue;
  1284             continue;
  1279         } /* if */
  1285         } /* if */
  1280 
  1286 
  1281         slash = strchr(add_file, '/'); /* handle subdirs under dirname... */
  1287         slash = strchr(add_file, '/'); /* handle subdirs under dirname... */
  1282         strsize = (size_t) ((slash) ? (slash - add_file) : strlen(add_file));
  1288         strsize = (size_t) ((slash) ? (slash - add_file) : strlen(add_file));
  1283 
       
  1284         retval = __PHYSFS_addToLinkedStringList(retval, &p, add_file, strsize);
  1289         retval = __PHYSFS_addToLinkedStringList(retval, &p, add_file, strsize);
  1285 
  1290 
  1286         if (++i >= max)
  1291         tmp = i;
  1287             break; /* we're at the end of the entries array. */
       
  1288 
       
  1289         if ((dlen > 0) && (strncmp(info->entries[i].name, dirname, dlen) != 0))
       
  1290             break; /* we're past this dir's entries. */
       
  1291 
       
  1292         /* We added a subdir? Skip its children. */
  1292         /* We added a subdir? Skip its children. */
  1293         while (slash != NULL)
  1293         while ((slash != NULL) && (i < max))
  1294         {
  1294         {
  1295             if (strncmp(info->entries[i].name, dirname, dlen) == 0)
  1295             if (strncmp(info->entries[i].name, info->entries[tmp].name, dlen + strsize + 1) == 0)
  1296             {
  1296             {
  1297                 if (info->entries[i].name[dlen] == '/')
  1297                 if (info->entries[i].name[dlen + strsize + 1] == '/')
  1298                 {
  1298                 {
  1299                     if (++i >= max) break; else continue;
  1299                     i++;
       
  1300                     continue;
  1300                 } /* if */
  1301                 } /* if */
  1301             } /* if */
  1302             } /* if */
       
  1303             i--;  /* for loop will increment. */
  1302             slash = NULL;
  1304             slash = NULL;
  1303         } /* while */
  1305         } /* while */
  1304     } /* while */
  1306     } /* while */
  1305 
  1307 
  1306     return(retval);
  1308     return(retval);
       
  1309 #endif
  1307 } /* ZIP_enumerateFiles */
  1310 } /* ZIP_enumerateFiles */
  1308 
  1311 
  1309 
  1312 
  1310 static int ZIP_exists(DirHandle *h, const char *name)
  1313 static int ZIP_exists(DirHandle *h, const char *name)
  1311 {
  1314 {