paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: paragui/src/physfs/platform macclassic.c,1.1.2.6,1.1


From: Alexander Pipelka <address@hidden>
Subject: [paragui-cvs] CVS: paragui/src/physfs/platform macclassic.c,1.1.2.6,1.1.2.7 pocketpc.c,1.1.2.1,1.1.2.2 posix.c,1.1.2.7,1.1.2.8 unix.c,1.1.1.1.6.9,1.1.1.1.6.10 win32.c,1.1.1.1.6.17,1.1.1.1.6.18
Date: Mon, 26 May 2003 03:39:56 -0400

Update of /cvsroot/paragui/paragui/src/physfs/platform
In directory subversions:/tmp/cvs-serv8619/src/physfs/platform

Modified Files:
      Tag: devel-1-0
        macclassic.c pocketpc.c posix.c unix.c win32.c 
Log Message:
- updated physfs version
- updated README files



Index: macclassic.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/macclassic.c,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -C2 -r1.1.2.6 -r1.1.2.7
*** macclassic.c        30 Jul 2002 20:50:27 -0000      1.1.2.6
--- macclassic.c        26 May 2003 07:39:53 -0000      1.1.2.7
***************
*** 11,14 ****
--- 11,15 ----
  #endif
  
+ #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
***************
*** 84,88 ****
          case vLckdErr: return(ERR_VOL_LOCKED_SW);
          case fBsyErr: return(ERR_FILE_OR_DIR_BUSY);
!         case dupFNErr: return(ERR_FILE_ALREADY_EXISTS);
          case opWrErr: return(ERR_FILE_ALREADY_OPEN_W);
          case rfNumErr: return(ERR_INVALID_REFNUM);
--- 85,89 ----
          case vLckdErr: return(ERR_VOL_LOCKED_SW);
          case fBsyErr: return(ERR_FILE_OR_DIR_BUSY);
!         case dupFNErr: return(ERR_FILE_EXISTS);
          case opWrErr: return(ERR_FILE_ALREADY_OPEN_W);
          case rfNumErr: return(ERR_INVALID_REFNUM);
***************
*** 105,109 ****
          case errFSNameTooLong: return(ERR_BAD_FILENAME);
          case errFSNotAFolder: return(ERR_NOT_A_DIR);
!         case errFSNotAFile: return(ERR_NOT_A_FILE);
          case fidNotFound: return(ERR_FILE_ID_NOT_FOUND);
          case fidExists: return(ERR_FILE_ID_EXISTS);
--- 106,110 ----
          case errFSNameTooLong: return(ERR_BAD_FILENAME);
          case errFSNotAFolder: return(ERR_NOT_A_DIR);
!         /*case errFSNotAFile: return(ERR_NOT_A_FILE);*/
          case fidNotFound: return(ERR_FILE_ID_NOT_FOUND);
          case fidExists: return(ERR_FILE_ID_EXISTS);
***************
*** 119,125 ****
          case errFSBadPosMode:
          case errFSBadAllocFlags:
!         case errFSBadItemCount
!         case errFSBadSearchParams
!         case afpDenyConflict
              return(ERR_PHYSFS_BAD_OS_CALL);
  
--- 120,126 ----
          case errFSBadPosMode:
          case errFSBadAllocFlags:
!         case errFSBadItemCount:
!         case errFSBadSearchParams:
!         case afpDenyConflict:
              return(ERR_PHYSFS_BAD_OS_CALL);
  
***************
*** 133,141 ****
  static OSErr oserr(OSErr retval)
  {
!     char buf[128];
      const char *errstr = get_macos_error_string(retval);
!     if (errstr == ERR_MACOS_GENERIC)
      {
!         snprintf(buf, ERR_MACOS_GENERIC, (int) retval);
          errstr = buf;
      } /* if */
--- 134,142 ----
  static OSErr oserr(OSErr retval)
  {
!     char buf[sizeof (ERR_MACOS_GENERIC) + 32];
      const char *errstr = get_macos_error_string(retval);
!     if (strcmp(errstr, ERR_MACOS_GENERIC) == 0)
      {
!         snprintf(buf, sizeof (buf), ERR_MACOS_GENERIC, (int) retval);
          errstr = buf;
      } /* if */
***************
*** 307,311 ****
      UseResFile(0);
      /* apparently, -16096 specifies the username. */
!     strHandle = oserr(GetString(-16096));
      UseResFile(origResourceFile);
      BAIL_IF_MACRO(strHandle == NULL, NULL, NULL);
--- 308,312 ----
      UseResFile(0);
      /* apparently, -16096 specifies the username. */
!     strHandle = GetString(-16096);
      UseResFile(origResourceFile);
      BAIL_IF_MACRO(strHandle == NULL, NULL, NULL);
***************
*** 595,599 ****
  
          /* still here? Add it to the list. */
!         ret = __PHYSFS_addToLinkedStringList(ret, &p, &str255[1], str255[0]);
      } /* for */
  
--- 596,600 ----
  
          /* still here? Add it to the list. */
!         ret = __PHYSFS_addToLinkedStringList(ret, &p, (const char *) 
&str255[1], str255[0]);
      } /* for */
  
***************
*** 668,672 ****
      } /* if */
  
!     err = HOpenDF(spec.vRefNum, spec.parID, spec.name, perm, retval)
      if (oserr(err) != noErr)
      {
--- 669,673 ----
      } /* if */
  
!     err = HOpenDF(spec.vRefNum, spec.parID, spec.name, perm, retval);
      if (oserr(err) != noErr)
      {

Index: pocketpc.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/Attic/pocketpc.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** pocketpc.c  3 Jan 2003 09:53:04 -0000       1.1.2.1
--- pocketpc.c  26 May 2003 07:39:53 -0000      1.1.2.2
***************
*** 27,30 ****
--- 27,31 ----
  
  const char *__PHYSFS_platformDirSeparator = "\\";
+ static char *userDir = NULL;
  
  /*
***************
*** 41,55 ****
  
      FormatMessage(
!         FORMAT_MESSAGE_FROM_SYSTEM |
!         FORMAT_MESSAGE_IGNORE_INSERTS,
!         NULL,
!         GetLastError(),
!         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
!         msgbuf,
!         sizeof (msgbuf) / sizeof (TCHAR),
!         NULL 
!     );
  
!         /* chop off newlines. */
      for (ptr = msgbuf; *ptr; ptr++)
      {
--- 42,56 ----
  
      FormatMessage(
!                 FORMAT_MESSAGE_FROM_SYSTEM |
!                 FORMAT_MESSAGE_IGNORE_INSERTS,
!                 NULL,
!                 GetLastError(),
!                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default 
language */
!                 msgbuf,
!                 sizeof (msgbuf) / sizeof (TCHAR),
!                 NULL 
!                 );
  
!     /* chop off newlines. */
      for (ptr = msgbuf; *ptr; ptr++)
      {
***************
*** 67,120 ****
  static char *UnicodeToAsc(const wchar_t *w_str)
  {
!       char *str=NULL;
  
!       if(w_str!=NULL)
!       {
!               int len=wcslen(w_str)+1;
!               str=(char *)malloc(len);
! 
!               if(WideCharToMultiByte(CP_ACP,0,w_str,-1,str,len,NULL,NULL)==0)
!               {       //Conversion failed
!                       free(str);
!                       return NULL;
!               }
!               else
!               {       //Conversion successful
!                       return(str);
!               }
  
        }
        else
!       {       //Given NULL string
!               return NULL;
        }
  }
  
  static wchar_t *AscToUnicode(const char *str)
  {
!       wchar_t *w_str=NULL;
!       if(str!=NULL)
        {
!               int len=strlen(str)+1;
!               w_str=(wchar_t *)malloc(sizeof(wchar_t)*len);
!               if(MultiByteToWideChar(CP_ACP,0,str,-1,w_str,len)==0)
!               {
!                       free(w_str);
!                       return NULL;
!               }
!               else
!               {
!                       return(w_str);
!               }
        }
        else
        {
!               return NULL;
        }
  }
  
  
  int __PHYSFS_platformInit(void)
  {
      return(1);  /* always succeed. */
  } /* __PHYSFS_platformInit */
--- 68,170 ----
  static char *UnicodeToAsc(const wchar_t *w_str)
  {
!     char *str=NULL;
  
!     if(w_str!=NULL)
!     {
!       int len=wcslen(w_str)+1;
!       str=(char *)malloc(len);
  
+       if(WideCharToMultiByte(CP_ACP,0,w_str,-1,str,len,NULL,NULL)==0)
+       {       //Conversion failed
+           free(str);
+           return NULL;
        }
        else
!       {       //Conversion successful
!           return(str);
        }
+ 
+     }
+     else
+     { //Given NULL string
+       return NULL;
+     }
  }
  
  static wchar_t *AscToUnicode(const char *str)
  {
!     wchar_t *w_str=NULL;
!     if(str!=NULL)
!     {
!       int len=strlen(str)+1;
!       w_str=(wchar_t *)malloc(sizeof(wchar_t)*len);
!       if(MultiByteToWideChar(CP_ACP,0,str,-1,w_str,len)==0)
        {
!           free(w_str);
!           return NULL;
        }
        else
        {
!           return(w_str);
        }
+     }
+     else
+     {
+       return NULL;
+     }
  }
  
  
+ static char *getExePath()
+ {
+     DWORD buflen;
+     int success = 0;
+     TCHAR *ptr = NULL;
+     TCHAR *retval = (TCHAR *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
+     char *charretval;
+     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
+ 
+     retval[0] = _T('\0');
+     buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
+     if (buflen <= 0) {
+         __PHYSFS_setError(win32strerror());
+     } else {
+         retval[buflen] = '\0';  /* does API always null-terminate this? */
+       ptr = retval+buflen;
+       while( ptr != retval )
+       {
+           if( *ptr != _T('\\') ) {
+               *ptr-- = _T('\0');
+           } else {
+               break;
+           }
+       }
+       success = 1;
+     } /* else */
+ 
+     if (!success)
+     {
+         free(retval);
+         return(NULL);  /* physfs error message will be set, above. */
+     } /* if */
+ 
+     /* free up the bytes we didn't actually use. */
+     ptr = (TCHAR *) realloc(retval, sizeof(TCHAR) * _tcslen(retval) + 1);
+     if (ptr != NULL)
+         retval = ptr;
+ 
+     charretval = UnicodeToAsc(retval);
+     free(retval);
+     if(charretval == NULL) {
+       BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
+     }
+     
+     return(charretval);   /* w00t. */
+ } /* getExePath */
+ 
  int __PHYSFS_platformInit(void)
  {
+     userDir = getExePath();
+     BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* failed? */
      return(1);  /* always succeed. */
  } /* __PHYSFS_platformInit */
***************
*** 123,126 ****
--- 173,177 ----
  int __PHYSFS_platformDeinit(void)
  {
+     free(userDir);
      return(1);  /* always succeed. */
  } /* __PHYSFS_platformDeinit */
***************
*** 135,140 ****
  char *__PHYSFS_platformCalcBaseDir(const char *argv0)
  {
!       return("\\");
! //    BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  } /* __PHYSFS_platformCalcBaseDir */
  
--- 186,190 ----
  char *__PHYSFS_platformCalcBaseDir(const char *argv0)
  {
!     return(getExePath());
  } /* __PHYSFS_platformCalcBaseDir */
  
***************
*** 148,152 ****
  char *__PHYSFS_platformGetUserDir(void)
  {
!       return("\\");
      BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  } /* __PHYSFS_platformGetUserDir */
--- 198,202 ----
  char *__PHYSFS_platformGetUserDir(void)
  {
!     return userDir;
      BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
  } /* __PHYSFS_platformGetUserDir */
***************
*** 161,173 ****
  int __PHYSFS_platformStricmp(const char *x, const char *y)
  {    
!       const char *p1 = x, *p2 = y;
!       int r = 0;
! 
!     while((*p1) && (*p2) && (toupper(*p1++) == toupper(*p2++)))  ++r;
! 
!     r = (!((*p1) || (*p2)) ? (0) : ((toupper(*p1) > toupper(*p2)) ?
!                                     (r + 1) : -(r + 1)));
! 
!     return(r);
  
  } /* __PHYSFS_platformStricmp */
--- 211,215 ----
  int __PHYSFS_platformStricmp(const char *x, const char *y)
  {    
!     return(_stricmp(x, y));
  
  } /* __PHYSFS_platformStricmp */
***************
*** 176,190 ****
  int __PHYSFS_platformExists(const char *fname)
  {
!       int retval=0;
  
!       wchar_t *w_fname=AscToUnicode(fname);
        
!       if(w_fname!=NULL)
!       {
!               retval=(GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
!               free(w_fname);
!       }
  
!       return(retval);
  } /* __PHYSFS_platformExists */
  
--- 218,232 ----
  int __PHYSFS_platformExists(const char *fname)
  {
!     int retval=0;
  
!     wchar_t *w_fname=AscToUnicode(fname);
        
!     if(w_fname!=NULL)
!     {
!       retval=(GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
!       free(w_fname);
!     }
  
!     return(retval);
  } /* __PHYSFS_platformExists */
  
***************
*** 198,212 ****
  int __PHYSFS_platformIsDirectory(const char *fname)
  {
!       int retval=0;
  
!       wchar_t *w_fname=AscToUnicode(fname);
  
!       if(w_fname!=NULL)
!       {
!           retval=((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 
0);
!               free(w_fname);
!       }
  
!       return(retval);
  } /* __PHYSFS_platformIsDirectory */
  
--- 240,254 ----
  int __PHYSFS_platformIsDirectory(const char *fname)
  {
!     int retval=0;
  
!     wchar_t *w_fname=AscToUnicode(fname);
  
!     if(w_fname!=NULL)
!     {
!       retval=((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
!       free(w_fname);
!     }
  
!     return(retval);
  } /* __PHYSFS_platformIsDirectory */
  
***************
*** 217,222 ****
  {
      int len = ((prepend) ? strlen(prepend) : 0) +
!               ((append) ? strlen(append) : 0) +
!               strlen(dirName) + 1;
      char *retval = malloc(len);
      char *p;
--- 259,264 ----
  {
      int len = ((prepend) ? strlen(prepend) : 0) +
!       ((append) ? strlen(append) : 0) +
!       strlen(dirName) + 1;
      char *retval = malloc(len);
      char *p;
***************
*** 256,260 ****
      WIN32_FIND_DATA ent;
      char *SearchPath;
!       wchar_t *w_SearchPath;
      size_t len = strlen(dirname);
  
--- 298,302 ----
      WIN32_FIND_DATA ent;
      char *SearchPath;
!     wchar_t *w_SearchPath;
      size_t len = strlen(dirname);
  
***************
*** 276,289 ****
      strcat(SearchPath, "*");
  
!       w_SearchPath=AscToUnicode(SearchPath);
  
      dir = FindFirstFile(w_SearchPath, &ent);
!       free(w_SearchPath);
!       free(SearchPath);
  
!       if(dir == INVALID_HANDLE_VALUE)
!       {
!               return NULL;
!       }
  
      do
--- 318,331 ----
      strcat(SearchPath, "*");
  
!     w_SearchPath=AscToUnicode(SearchPath);
  
      dir = FindFirstFile(w_SearchPath, &ent);
!     free(w_SearchPath);
!     free(SearchPath);
  
!     if(dir == INVALID_HANDLE_VALUE)
!     {
!       return NULL;
!     }
  
      do
***************
*** 299,303 ****
              break;
  
!               l->str=UnicodeToAsc(ent.cFileName);
  
          if (l->str == NULL)
--- 341,345 ----
              break;
  
!       l->str=UnicodeToAsc(ent.cFileName);
  
          if (l->str == NULL)
***************
*** 324,328 ****
  char *__PHYSFS_platformCurrentDir(void)
  {
!       return("\\");
  } /* __PHYSFS_platformCurrentDir */
  
--- 366,370 ----
  char *__PHYSFS_platformCurrentDir(void)
  {
!     return("\\");
  } /* __PHYSFS_platformCurrentDir */
  
***************
*** 330,338 ****
  char *__PHYSFS_platformRealPath(const char *path)
  {
!       char *retval=(char *)malloc(strlen(path)+1);
  
!       strcpy(retval,path);
  
!       return(retval);
  
  } /* __PHYSFS_platformRealPath */
--- 372,380 ----
  char *__PHYSFS_platformRealPath(const char *path)
  {
!     char *retval=(char *)malloc(strlen(path)+1);
  
!     strcpy(retval,path);
  
!     return(retval);
  
  } /* __PHYSFS_platformRealPath */
***************
*** 341,359 ****
  int __PHYSFS_platformMkDir(const char *path)
  {
!       wchar_t *w_path = AscToUnicode(path);
!       if(w_path!=NULL)
!       {
!           DWORD rc = CreateDirectory(w_path, NULL);
!               free(w_path);
!               if(rc==0)
!               {
!                       return(0);
!               }
!               return(1);
!       }
!       else
        {
!               return(0);
        }
  } /* __PHYSFS_platformMkDir */
  
--- 383,401 ----
  int __PHYSFS_platformMkDir(const char *path)
  {
!     wchar_t *w_path = AscToUnicode(path);
!     if(w_path!=NULL)
!     {
!       DWORD rc = CreateDirectory(w_path, NULL);
!       free(w_path);
!       if(rc==0)
        {
!           return(0);
        }
+       return(1);
+     }
+     else
+     {
+       return(0);
+     }
  } /* __PHYSFS_platformMkDir */
  
***************
*** 363,390 ****
      HANDLE fileHandle;
      winCEfile *retval;
!       wchar_t *w_fname=AscToUnicode(fname);
  
      fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL,
                              creation, FILE_ATTRIBUTE_NORMAL, NULL);
  
!       free(w_fname);
  
!       if(fileHandle==INVALID_HANDLE_VALUE)
!       {
!               return NULL;
!       }
  
      BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
  
!       retval = malloc(sizeof (winCEfile));
!       if (retval == NULL)
!       {
!               CloseHandle(fileHandle);
!               BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
!       } /* if */
! 
!       retval->readonly = rdonly;
!       retval->handle = fileHandle;
!       return(retval);
  } /* doOpen */
  
--- 405,432 ----
      HANDLE fileHandle;
      winCEfile *retval;
!     wchar_t *w_fname=AscToUnicode(fname);
  
      fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL,
                              creation, FILE_ATTRIBUTE_NORMAL, NULL);
  
!     free(w_fname);
  
!     if(fileHandle==INVALID_HANDLE_VALUE)
!     {
!       return NULL;
!     }
  
      BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
  
!     retval = malloc(sizeof (winCEfile));
!     if (retval == NULL)
!     {
!       CloseHandle(fileHandle);
!       BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
!     } /* if */
! 
!     retval->readonly = rdonly;
!     retval->handle = fileHandle;
!     return(retval);
  } /* doOpen */
  
***************
*** 433,437 ****
      if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL))
      {
!               retval=-1;
      } /* if */
      else
--- 475,479 ----
      if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL))
      {
!       retval=-1;
      } /* if */
      else
***************
*** 458,462 ****
      if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten, 
NULL))
      {
!               retval=-1;
      } /* if */
      else
--- 500,504 ----
      if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten, 
NULL))
      {
!       retval=-1;
      } /* if */
      else
***************
*** 467,471 ****
      } /* else */
  
!       return(retval);
  
  } /* __PHYSFS_platformWrite */
--- 509,513 ----
      } /* else */
  
!     return(retval);
  
  } /* __PHYSFS_platformWrite */
***************
*** 480,484 ****
      /* Get the high order 32-bits of the position */
      //HighOrderPos = HIGHORDER_UINT64(pos);
!       HighOrderPos = (unsigned long)(pos>>32);
  
      /*!!! SetFilePointer needs a signed 64-bit value. */
--- 522,526 ----
      /* Get the high order 32-bits of the position */
      //HighOrderPos = HIGHORDER_UINT64(pos);
!     HighOrderPos = (unsigned long)(pos>>32);
  
      /*!!! SetFilePointer needs a signed 64-bit value. */
***************
*** 488,494 ****
  
      if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
!       {
          BAIL_MACRO(win32strerror(), 0);
!       }
  
      return(1);  /* No error occured */
--- 530,536 ----
  
      if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
!     {
          BAIL_MACRO(win32strerror(), 0);
!     }
  
      return(1);  /* No error occured */
***************
*** 580,596 ****
  int __PHYSFS_platformDelete(const char *path)
  {
!       wchar_t *w_path=AscToUnicode(path);
  
      /* If filename is a folder */
      if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
      {
!               int retval=!RemoveDirectory(w_path);
!               free(w_path);
          BAIL_IF_MACRO(retval, win32strerror(), 0);
      } /* if */
      else
      {
!               int retval=!DeleteFile(w_path);
!               free(w_path);
          BAIL_IF_MACRO(retval, win32strerror(), 0);
      } /* else */
--- 622,638 ----
  int __PHYSFS_platformDelete(const char *path)
  {
!     wchar_t *w_path=AscToUnicode(path);
  
      /* If filename is a folder */
      if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
      {
!       int retval=!RemoveDirectory(w_path);
!       free(w_path);
          BAIL_IF_MACRO(retval, win32strerror(), 0);
      } /* if */
      else
      {
!       int retval=!DeleteFile(w_path);
!       free(w_path);
          BAIL_IF_MACRO(retval, win32strerror(), 0);
      } /* else */

Index: posix.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/posix.c,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -C2 -r1.1.2.7 -r1.1.2.8
*** posix.c     3 Jan 2003 09:53:04 -0000       1.1.2.7
--- posix.c     26 May 2003 07:39:53 -0000      1.1.2.8
***************
*** 132,139 ****
          ux = toupper((int) *x);
          uy = toupper((int) *y);
!         if (ux > uy)
!             return(1);
!         else if (ux < uy)
!             return(-1);
          x++;
          y++;
--- 132,137 ----
          ux = toupper((int) *x);
          uy = toupper((int) *y);
!         if (ux != uy)
!             return((ux > uy) ? 1 : -1);
          x++;
          y++;

Index: unix.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/unix.c,v
retrieving revision 1.1.1.1.6.9
retrieving revision 1.1.1.1.6.10
diff -C2 -r1.1.1.1.6.9 -r1.1.1.1.6.10
*** unix.c      6 Dec 2002 17:54:52 -0000       1.1.1.1.6.9
--- unix.c      26 May 2003 07:39:53 -0000      1.1.1.1.6.10
***************
*** 28,31 ****
--- 28,43 ----
  #include <sys/mount.h>
  
+ #ifndef PHYSFS_DARWIN
+ #  if defined(__MACH__) && defined(__APPLE__)
+ #    define PHYSFS_DARWIN 1
+ #    include <CoreFoundation/CoreFoundation.h>
+ #    include <CoreServices/CoreServices.h>
+ #    include <IOKit/IOKitLib.h>
+ #    include <IOKit/storage/IOMedia.h>
+ #    include <IOKit/storage/IOCDMedia.h>
+ #    include <IOKit/storage/IODVDMedia.h>
+ #  endif
+ #endif
+ 
  #if (!defined PHYSFS_NO_PTHREADS_SUPPORT)
  #include <pthread.h>
***************
*** 73,80 ****
  } /* __PHYSFS_platformDetectAvailableCDs */
  
- #else
  
  
! #ifdef PHYSFS_HAVE_SYS_UCRED_H
  
  char **__PHYSFS_platformDetectAvailableCDs(void)
--- 85,215 ----
  } /* __PHYSFS_platformDetectAvailableCDs */
  
  
+ #elif (defined PHYSFS_DARWIN)  /* "Big Nasty." */
+ /*
+  * Code based on sample from Apple Developer Connection:
+  *  
http://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/Disks/VolumeToBSDNode/VolumeToBSDNode.c.htm
+  */
+ 
+ static int darwinIsWholeMedia(io_service_t service)
+ {
+     int retval = 0;
+     CFTypeRef wholeMedia;
+ 
+     if (!IOObjectConformsTo(service, kIOMediaClass))
+         return(0);
+         
+     wholeMedia = IORegistryEntryCreateCFProperty(service,
+                                                  CFSTR(kIOMediaWholeKey),
+                                                  kCFAllocatorDefault, 0);
+     if (wholeMedia == NULL)
+         return(0);
+ 
+     retval = CFBooleanGetValue(wholeMedia);
+     CFRelease(wholeMedia);
+ 
+     return retval;
+ } /* darwinIsWholeMedia */
+ 
+ 
+ static int darwinIsMountedDisc(char *bsdName, mach_port_t masterPort)
+ {
+     int retval = 0;
+     CFMutableDictionaryRef matchingDict;
+     kern_return_t rc;
+     io_iterator_t iter;
+     io_service_t service;
+ 
+     if ((matchingDict = IOBSDNameMatching(masterPort, 0, bsdName)) == NULL)
+         return(0);
+ 
+     rc = IOServiceGetMatchingServices(masterPort, matchingDict, &iter);
+     if ((rc != KERN_SUCCESS) || (!iter))
+         return(0);
+ 
+     service = IOIteratorNext(iter);
+     IOObjectRelease(iter);
+     if (!service)
+         return(0);
+ 
+     rc = IORegistryEntryCreateIterator(service, kIOServicePlane,
+              kIORegistryIterateRecursively | kIORegistryIterateParents, 
&iter);
+     
+     if (!iter)
+         return(0);
+ 
+     if (rc != KERN_SUCCESS)
+     {
+         IOObjectRelease(iter);
+         return(0);
+     } /* if */
+ 
+     IOObjectRetain(service);  /* add an extra object reference... */
+ 
+     do
+     {
+         if (darwinIsWholeMedia(service))
+         {
+             if ( (IOObjectConformsTo(service, kIOCDMediaClass)) ||
+                  (IOObjectConformsTo(service, kIODVDMediaClass)) )
+             {
+                 retval = 1;
+             } /* if */
+         } /* if */
+         IOObjectRelease(service);
+     } while ((service = IOIteratorNext(iter)) && (!retval));
+                 
+     IOObjectRelease(iter);
+     IOObjectRelease(service);
+ 
+     return(retval);
+ } /* darwinIsMountedDisc */
  
! 
! char **__PHYSFS_platformDetectAvailableCDs(void)
! {
!     const char *devPrefix = "/dev/";
!     int prefixLen = strlen(devPrefix);
!     mach_port_t masterPort = 0;
!     char **retval = (char **) malloc(sizeof (char *));
!     int cd_count = 1;  /* We count the NULL entry. */
!     struct statfs *mntbufp;
!     int i, mounts;
! 
!     retval[0] = NULL;
! 
!     if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS)
!         return(retval);
! 
!     mounts = getmntinfo(&mntbufp, MNT_WAIT);  /* NOT THREAD SAFE! */
!     for (i = 0; i < mounts; i++)
!     {
!         char *dev = mntbufp[i].f_mntfromname;
!         char *mnt = mntbufp[i].f_mntonname;
!         if (strncmp(dev, devPrefix, prefixLen) != 0)  /* a virtual device? */
!             continue;
! 
!         dev += prefixLen;
!         if (darwinIsMountedDisc(dev, masterPort))
!         {
!             char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1));
!             if (tmp)
!             {
!                 retval = tmp;
!                 retval[cd_count - 1] = (char *) malloc(strlen(mnt) + 1);
!                 if (retval[cd_count - 1])
!                 {
!                     strcpy(retval[cd_count - 1], mnt);
!                     cd_count++;
!                 } /* if */
!             } /* if */
!         } /* if */
!     } /* for */
! 
!     retval[cd_count - 1] = NULL;
!     return(retval);
! } /* __PHYSFS_platformDetectAvailableCDs */
! 
! #elif (defined PHYSFS_HAVE_SYS_UCRED_H)
  
  char **__PHYSFS_platformDetectAvailableCDs(void)
***************
*** 122,129 ****
  } /* __PHYSFS_platformDetectAvailableCDs */
  
! #endif
! 
! 
! #ifdef PHYSFS_HAVE_MNTENT_H
  
  char **__PHYSFS_platformDetectAvailableCDs(void)
--- 257,261 ----
  } /* __PHYSFS_platformDetectAvailableCDs */
  
! #elif (defined PHYSFS_HAVE_MNTENT_H)
  
  char **__PHYSFS_platformDetectAvailableCDs(void)
***************
*** 172,177 ****
  #endif
  
- #endif  /* !PHYSFS_NO_CDROM_SUPPORT */
- 
  
  /* this is in posix.c ... */
--- 304,307 ----
***************
*** 267,270 ****
--- 397,498 ----
  
  
+ #if PHYSFS_DARWIN
+ /* 
+  * This function is only for OSX. The problem is that Apple's applications
+  * can actually be directory structures with the actual executable nested
+  * several levels down. PhysFS computes the base directory from the Unix
+  * executable, but this may not be the correct directory. Apple tries to
+  * hide everything from the user, so from Finder, the user never sees the
+  * Unix executable, and the directory package (bundle) is considered the
+  * "executable". This means that the correct base directory is at the 
+  * level where the directory structure starts.
+  * A typical bundle seems to look like this:
+  * MyApp.app/    <-- top level...this is what the user sees in Finder 
+  *   Contents/
+  *     MacOS/
+  *       MyApp   <-- the actual executable
+  *       
+  * Since anything below the app folder is considered hidden, most 
+  * application files need to be at the top level if you intend to
+  * write portable software. Thus if the application resides in:
+  * /Applications/MyProgram
+  * and the executable is the bundle MyApp.app,
+  * PhysFS computes the following as the base directory:
+  * /Applications/MyProgram/MyApp.app/Contents/MacOS/
+  * We need to strip off the MyApp.app/Contents/MacOS/
+  * 
+  * However, there are corner cases. OSX applications can be traditional
+  * Unix executables without the bundle. Also, it is not entirely clear
+  * to me what kinds of permutations bundle structures can have.
+  * 
+  * For now, this is a temporary hack until a better solution 
+  * can be made. This function will try to find a "/Contents/MacOS"
+  * inside the path. If it succeeds, then the path will be truncated
+  * to correct the directory. If it is not found, the path will be 
+  * left alone and will presume it is a traditional Unix execuatable.
+  * Most programs also include the .app extention in the top level
+  * folder, but it doesn't seem to be a requirement (Acrobat doesn't 
+  * have it). MacOS looks like it can also be MacOSClassic. 
+  * This function will test for MacOS and hope it captures any
+  * other permutations.
+  */
+ static void stripAppleBundle(char *path)
+ {
+     char *sub_str = "/contents/macos";
+     char *found_ptr = NULL;
+     char *tempbuf = NULL;
+     int i;
+     
+     /* Calloc will place the \0 character in the proper place for us */
+     /* !!! FIXME: Can we stack-allocate this? --ryan. */
+     tempbuf = (char*)calloc( (strlen(path)+1), sizeof(char) );
+     /* Unlike other Unix filesystems, HFS is case insensitive
+      * It wouldn be nice to use strcasestr, but it doesn't seem
+      * to be available in the OSX gcc library right now.
+      * So we should make a lower case copy of the path to 
+      * compare against 
+      */
+     for(i=0; i<strlen(path); i++)
+     {
+         /* convert to lower case */
+         tempbuf[i] = tolower(path[i]);
+     }
+     /* See if we can find "/contents/macos" in the path */
+     found_ptr = strstr(tempbuf, sub_str);
+     if(NULL == found_ptr)
+     {
+         /* It doesn't look like a bundle so we can keep the 
+          * original path. Just return */
+         free(tempbuf);
+         return;
+     }
+     /* We have a bundle, so let's backstep character by character
+      * to erase the extra parts of the path. Quit when we hit
+      * the preceding '/' character.
+      */
+     for(i=strlen(path)-strlen(found_ptr)-1; i>=0; i--)
+     {
+         if('/' == path[i])
+         {
+             break;
+         }
+     }
+     /* Safety check */
+     if(i<1)
+     {
+         /* This probably shouldn't happen. */
+         path[0] = '\0';
+     }
+     else
+     {
+         /* Back up one more to remove trailing '/' and set the '\0' */
+         path[i] = '\0';
+     }
+     free(tempbuf);
+     return;
+ }
+ #endif /* defined __MACH__ && defined __APPLE__ */
+ 
+ 
  char *__PHYSFS_platformRealPath(const char *path)
  {
***************
*** 277,280 ****
--- 505,513 ----
      BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
      strcpy(retval, resolved_path);
+ 
+ #if defined(__MACH__) && defined(__APPLE__)
+     stripAppleBundle(retval);
+ #endif /* defined __MACH__ && defined __APPLE__ */
+     
      return(retval);
  } /* __PHYSFS_platformRealPath */

Index: win32.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/win32.c,v
retrieving revision 1.1.1.1.6.17
retrieving revision 1.1.1.1.6.18
diff -C2 -r1.1.1.1.6.17 -r1.1.1.1.6.18
*** win32.c     27 Jan 2003 13:39:08 -0000      1.1.1.1.6.17
--- win32.c     26 May 2003 07:39:53 -0000      1.1.1.1.6.18
***************
*** 127,131 ****
              /* make sure the string was not truncated. */
          if (__PHYSFS_platformStricmp(&retval[buflen - 4], ".exe") != 0)
- //            __PHYSFS_setError(ERR_GETMODFN_NO_DIR);
              __PHYSFS_setError(ERR_GETMODFN_TRUNC);
          else
--- 127,130 ----
***************
*** 302,307 ****
  char *__PHYSFS_platformCalcBaseDir(const char *argv0)
  {
!     if (strchr(argv0, '\\') != NULL)   /* default behaviour can handle this. 
*/
!         return(NULL);
  
      return(getExePath(argv0));
--- 301,306 ----
  char *__PHYSFS_platformCalcBaseDir(const char *argv0)
  {
!     if ((argv0 != NULL) && (strchr(argv0, '\\') != NULL))
!         return(NULL); /* default behaviour can handle this. */
  
      return(getExePath(argv0));





reply via email to

[Prev in Thread] Current Thread [Next in Thread]