Better cacao_create_directoryList code and only add *.class files to the
authortwisti <none@none>
Tue, 1 Feb 2005 08:49:00 +0000 (08:49 +0000)
committertwisti <none@none>
Tue, 1 Feb 2005 08:49:00 +0000 (08:49 +0000)
directory list.

src/vm/unzip.c

index 2bebe0ade8038c29f2905139a92ec3e807d78fc2..576ebedec1b92a99fea60908377d87543f4be0a1 100644 (file)
@@ -706,48 +706,35 @@ void cacao_create_directoryList(unzFile file)
   cacao_entry_s *ent;
   unz_s *s=(unz_s*)file;
   char *c;
-  int i;
   unz_file_info tmp;
   char filename[200];
 
-  if (unzGoToFirstFile(file) != UNZ_OK) {
-    s->cacao_dir_list = NULL;
+  s->cacao_dir_list = NULL;
+
+  if (unzGoToFirstFile(file) != UNZ_OK)
     return;
-  }
 
-  i = 0;
-  ent = s->cacao_dir_list = NEW(cacao_entry_s);
-  ent->next = NULL;
-  ent->pos = s->pos_in_central_dir;
+  do {
+    if (unzGetCurrentFileInfo(file, &tmp, filename, 200, 0, 0, 0, 0) != UNZ_OK)
+      panic("Error in ZIP archive");
 
-  if (unzGetCurrentFileInfo(file, &tmp, filename, 200, 0, 0, 0, 0) != UNZ_OK) {
-    panic("Error in ZIP archive");
-  }
+    if ((c = strstr(filename, ".class"))) {
+      *c = '\0';
 
-  c = strstr(filename, ".class");
-  if (c)
-    *c = '\0';
+      if (!s->cacao_dir_list) {
+        ent = s->cacao_dir_list = NEW(cacao_entry_s);
 
-  ent->name = utf_new_char(filename);
+      } else {
+        ent->next = NEW(cacao_entry_s);
+        ent = ent->next;
+      }
 
-  while (unzGoToNextFile(file) == UNZ_OK) {
-    i++;
-    ent->next = NEW(cacao_entry_s);
-    ent = ent->next;
-    ent->next = NULL;
-    ent->pos = s->pos_in_central_dir;
+      ent->next = NULL;
 
-    if (unzGetCurrentFileInfo(file, &tmp, filename, 200, 0, 0, 0, 0) != UNZ_OK) {
-      panic("Error in ZIP archive");
+      ent->name = utf_new_char(filename);
+      ent->pos = s->pos_in_central_dir;
     }
-
-    c = strstr(filename, ".class");
-    if (c)
-      *c = '\0';
-
-    ent->name = utf_new_char(filename);
-  }
-  /*printf("Archive contains %d files\n",i);*/
+  } while (unzGoToNextFile(file) == UNZ_OK);
 }