All pastes #395130 Raw Edit

ZSNES File Speedpatc

public text v1 · immutable
·published 2007-03-14 20:40 UTC
rendered paste body
Index: Makefile.in
===================================================================
--- Makefile.in (revision 4839)
+++ Makefile.in (working copy)
@@ -60,8 +60,8 @@
 JMA_CO=@JMA_FILES@

 MAIN_AO=@DEBUGGER_A@ endmem.o init.o vcache.o ztime.o
-MAIN_CO=cfg.o @DEBUGGER_C@ initc.o input.o md.o patch.o ui.o version.o zloader.o\
-       zmovie.o zpath.o zstate.o ztimec.o
+MAIN_CO=cfg.o @DEBUGGER_C@ initc.o input.o md.o patch.o ui.o version.o zdir.o\
+       zloader.o zmovie.o zpath.o zstate.o ztimec.o

 MMLIB_CO=@MMLIB_FILES@

Index: gui/guifuncs.c
===================================================================
--- gui/guifuncs.c      (revision 4839)
+++ gui/guifuncs.c      (working copy)
@@ -46,7 +46,6 @@

 #ifndef _MSC_VER
 #include <stdint.h>
-#include <dirent.h>
 #include <unistd.h>
 #endif

@@ -56,6 +55,7 @@
 #include "../input.h"
 #include "../asm_call.h"
 #include "../zloader.h"
+#include "../zdir.h"

 #define BIT(X) (1 << (X))

@@ -889,21 +889,21 @@
 #define INFO_LEN (0xFF - 0xC0)
 #define INAME_LEN 21

-static const char *get_rom_name(const char *filename, char *namebuffer, struct stat *filestats)
+static const char *get_rom_name(struct dirent_info *entry, char *namebuffer)
 {
   int InfoScore(char *);
   unsigned int sum(unsigned char *array, unsigned int size);

-  char *last_dot = strrchr(filename, '.');
+  char *last_dot = strrchr(entry->name, '.');
   if (!last_dot || (strcasecmp(last_dot, ".zip") && strcasecmp(last_dot, ".gz") && strcasecmp(last_dot, ".jma")))
   {
-    if ((filestats->st_size >= 0x8000) && (filestats->st_size <= 0x600000+HEADER_SIZE))
+    if ((entry->size >= 0x8000) && (entry->size <= 0x600000+HEADER_SIZE))
     {
-      FILE *fp = fopen_dir(ZRomPath, filename, "rb");
+      FILE *fp = fopen_dir(ZRomPath, entry->name, "rb");
       if (fp)
       {
         unsigned char HeaderBuffer[HEADER_SIZE];
-        int HeaderSize = 0, HasHeadScore = 0, NoHeadScore = 0, HeadRemain = filestats->st_size & 0x7FFF;
+        int HeaderSize = 0, HasHeadScore = 0, NoHeadScore = 0, HeadRemain = entry->size & 0x7FFF;
         bool EHi = false;

         switch(HeadRemain)
@@ -945,7 +945,7 @@

         HeaderSize = HasHeadScore > NoHeadScore ? HEADER_SIZE : 0;

-        if (filestats->st_size - HeaderSize >= 0x500000)
+        if (entry->size - HeaderSize >= 0x500000)
         {
           fseek(fp, 0x40FFC0 + HeaderSize, SEEK_SET);
           fread(HeaderBuffer, 1, INFO_LEN, fp);
@@ -958,7 +958,7 @@

         if (!EHi)
         {
-          if (filestats->st_size - HeaderSize >= 0x10000)
+          if (entry->size - HeaderSize >= 0x10000)
           {
             char LoHead[INFO_LEN], HiHead[INFO_LEN];
             int LoScore, HiScore;
@@ -973,10 +973,10 @@

             strncpy(namebuffer, LoScore > HiScore ? LoHead : HiHead, INAME_LEN);

-            if (filestats->st_size - HeaderSize >= 0x20000)
+            if (entry->size - HeaderSize >= 0x20000)
             {
               int IntLScore;
-              fseek(fp, (filestats->st_size - HeaderSize) / 2 + 0x7FC0 + HeaderSize, SEEK_SET);
+              fseek(fp, (entry->size - HeaderSize) / 2 + 0x7FC0 + HeaderSize, SEEK_SET);
               fread(LoHead, 1, INFO_LEN, fp);
               IntLScore = InfoScore(LoHead) / 2;

@@ -1006,7 +1006,7 @@
   }
   else //Compressed archive
   {
-    return(filename);
+    return(entry->name);
   }
   namebuffer[21] = 0;
   return(namebuffer);
@@ -1142,31 +1142,30 @@

   if ((dir = opendir(ZRomPath)))
   {
-    struct stat stat_buffer;
-    struct dirent *entry;
+    struct dirent_info *entry;

-    while ((entry = readdir(dir)))
+    while ((entry = readdir_info(dir)))
     {
-      if ((*entry->d_name != '.') && !stat_dir(ZRomPath, entry->d_name, &stat_buffer))
+      if (*entry->name != '.')
       {
-        if (S_ISDIR(stat_buffer.st_mode))
+        if (S_ISDIR(entry->mode))
         {
           if (lists&LIST_DN)
           {
-            add_list(&d_names, entry->d_name);
+            add_list(&d_names, entry->name);
           }
         }
-        else if (!snes_ext_match || snes_extension_match(entry->d_name))
+        else if (!snes_ext_match || snes_extension_match(entry->name))
         {
           if (_USE_LFN && (lists&LIST_LFN))
           {
-            add_list(&lf_names, entry->d_name);
+            add_list(&lf_names, entry->name);
           }

           if (lists&LIST_IN)
           {
             char namebuffer[22];
-            add_list(&i_names, get_rom_name(entry->d_name, namebuffer, &stat_buffer));
+            add_list(&i_names, get_rom_name(entry, namebuffer));
           }

 #ifdef __MSDOS__
@@ -1174,11 +1173,11 @@
           {
             if (!_USE_LFN) //_USE_LFN won't be true when running under pure DOS
             {
-              add_list(&et_names, entry->d_name);
+              add_list(&et_names, entry->name);
             }
             else
             {
-              char *sfn = realpath_sfn_dir(ZRomPath, entry->d_name, 0);
+              char *sfn = realpath_sfn_dir(ZRomPath, entry->name, 0);
               if (sfn)
               {
                 add_list(&et_names, basename(sfn));
@@ -1187,7 +1186,7 @@
               else
               {
                 char sfn[13];
-                _lfn_gen_short_fname(entry->d_name, sfn);
+                _lfn_gen_short_fname(entry->name, sfn);
                 add_list(&et_names, sfn);
               }
             }
Index: zmovie.c
===================================================================
--- zmovie.c    (revision 4839)
+++ zmovie.c    (working copy)
@@ -42,14 +42,12 @@
 #include <io.h>
 #define ftruncate chsize
 #include "win/safelib.h"
-#include "win/lib.h"
 #endif
 #define DIR_SLASH "\\"
 #define WRITE_BINARY "wb"
 #define NULL_FILE "nul"
 #endif
 #ifndef _MSC_VER
-#include <dirent.h>
 #include <unistd.h>
 #endif
 #include "gblvars.h"
@@ -60,6 +58,7 @@
 #include "zpath.h"
 #include "zmovie.h"
 #include "cpu/dspwrap.h"
+#include "zdir.h"

 #define NUMCONV_FR2
 #define NUMCONV_FR3
Index: makefile.ms
===================================================================
--- makefile.ms (revision 4839)
+++ makefile.ms (working copy)
@@ -205,7 +205,7 @@

 MAINOBJ=endmem${OE} init${OE} initc${OE} patch${OE} ui${OE} vcache${OE}\
        version${OE} zmovie${OE} zstate${OE} zloader${OE} cfg${OE} md${OE}\
-       input${OE} zpath${OE} ztimec${OE} ztime${OE}
+       input${OE} zdir${OE} zpath${OE} ztimec${OE} ztime${OE}

 ifneq (${DEBUGGER},no)
   MAINOBJ+= debugger${OE} debugasm${OE}
@@ -318,11 +318,12 @@
        ${MMLIB_D}/mm.h ${ZIP_D}/zunzip.h
 vcache${OE}: vcache.asm macros.mac
 version${OE}: version.c
+zdir${OE}: zdir.h zpath.h
 zloader${OE}: zloader.c asm_call.h cfg${OE} input${OE} zloader.h zpath.h \
        ${JMA_D}/zsnesjma.h ${ZIP_D}/zunzip.h
 zmovie${OE}: zmovie.c asm_call.h cfg${OE} gblvars.h input${OE} md${OE} \
        numconv.h zmovie.h zpath.h ${CPU_D}/dspwrap.h ${JMA_D}/zsnesjma.h \
-       ${WIN_D}/lib.h ${WIN_D}/safelib.h ${ZIP_D}/zunzip.h
+       zdir.h ${WIN_D}/safelib.h ${ZIP_D}/zunzip.h
 zpath${OE}: zpath.c cfg${OE} zpath.h ${DOS_D}/lib.h ${JMA_D}/zsnesjma.h \
        ${WIN_D}/lib.h ${WIN_D}/safelib.h ${ZIP_D}/zunzip.h ${CONFLOC}
 zstate${OE}: zstate.c asm_call.h cfg${OE} gblvars.h input${OE} numconv.h \
Index: win/lib.c
===================================================================
--- win/lib.c   (revision 4839)
+++ win/lib.c   (working copy)
@@ -30,88 +30,6 @@

 //This file contains library functions that can be found on other OSs

-
-#ifdef _MSC_VER
-
-DIR *opendir(const char *path)
-{
-  DIR *dir = 0;
-  if (path && *path)
-  {
-    char search[MAX_PATH];
-    strcpy(search, path);
-    strcatslash(search);
-    strcat(search, "*");
-
-    dir = malloc(sizeof(DIR));
-    if (dir)
-    {
-      dir->find_first_handle = _findfirst(search, &dir->fileinfo);
-      if (dir->find_first_handle == -1)
-      {
-        //ENOENT set by findfirst already
-        free(dir);
-        dir = 0;
-      }
-    }
-    else
-    {
-      errno = ENOMEM;
-    }
-  }
-  else
-  {
-      errno = EINVAL;
-  }
-
-  return(dir);
-}
-
-struct dirent *readdir(DIR *dir)
-{
-  struct dirent *entry = 0;
-  if (dir->find_first_handle != -1)
-  {
-    entry = &dir->entry;
-    strcpy(entry->d_name, dir->fileinfo.name);
-    if (_findnext(dir->find_first_handle, &dir->fileinfo) == -1)
-    {
-      _findclose(dir->find_first_handle);
-      dir->find_first_handle = -1;
-    }
-  }
-  else
-  {
-    errno = EBADF;
-  }
-
-  return(entry);
-}
-
-int closedir(DIR *dir)
-{
-  int result = 0;
-
-  if (dir)
-  {
-    if (dir->find_first_handle != -1)
-    {
-      _findclose(dir->find_first_handle);
-    }
-    free(dir);
-  }
-  else
-  {
-    result = -1;
-    errno = EBADF;
-  }
-
-  return(result);
-}
-
-#endif
-
-
 char *realpath(const char *path, char *resolved_path)
 {
   char *ret = 0;
Index: win/lib.h
===================================================================
--- win/lib.h   (revision 4839)
+++ win/lib.h   (working copy)
@@ -28,23 +28,6 @@
 #ifdef _MSC_VER
 #define strcasecmp stricmp
 #define strncasecmp strnicmp
-
-struct dirent
-{
-  char d_name[256];
-};
-
-typedef struct
-{
-  intptr_t find_first_handle;
-  struct _finddata_t fileinfo;
-  struct dirent entry;
-} DIR;
-
-DIR *opendir(const char *path);
-struct dirent *readdir(DIR *dir);
-int closedir(DIR *dir);
-
 #endif

 char *realpath(const char *path, char *resolved_path);