From 7aa0c252a9d7fe8cd99b16c5792583d00ff0fe6a Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 23 Aug 2001 16:02:51 +0000 Subject: [PATCH] More win32 updates. --- CHANGELOG | 5 ++-- INSTALL | 23 ++++++++++++++- Makefile | 5 ++++ archivers/zip.c | 4 +-- platform/win32.c | 77 +++++++++++++++++++++--------------------------- 5 files changed, 65 insertions(+), 49 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 14f653c4..3f33a701 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,8 +11,9 @@ platform/win32.c. Other cleanups to get this compiling with Visual C and CygWin. Added BAIL_MACRO for times when we were doing BAIL_IF_MACRO(1, ...). Abstracted mkdir() in the platform drivers. - Added GRP setting output to showcfg in the Makefile. Changed - version to 0.1.2. + Added GRP setting output to showcfg in the Makefile. Updated INSTALL + with license info and Win32 build instructions. + Changed version to 0.1.2. --ryan. (icculus@clutteredmind.org) diff --git a/INSTALL b/INSTALL index 02476481..46776767 100644 --- a/INSTALL +++ b/INSTALL @@ -1,7 +1,20 @@ Building is very easy. + +ALL PLATFORMS: + +Please understand your rights and mine: read the text file LICENSE in the root +of the source tree. If you can't abide by it, delete this source tree now. + +The best documentation for the PhysicsFS API is physfs.h. It is VERY heavily +commented, and makes an excellent, in-depth reference to all the functions. + + +UNIX: + Edit "Makefile", and follow the instructions. The defaults are probably okay -for general purposes, but give it a once over to make sure. +for general purposes, but give it a once over to make sure. If you don't have +zLib on your system, you'll need to disable ZIP support. run "make" @@ -9,5 +22,13 @@ That's it. The library will be sitting in a new directory called "bin". Run "make install" to install the library for use on your system. + +WIN32: +If building with CygWin, follow the Unix instructions, above. If you're using +Visual C, unzip VisualC.zip so that the project files end up in the same +directory as physfs.c, and point Visual C at that project to build. If you're +using any other compiler, send me a patch when you get it working. :) + --ryan. (icculus@clutteredmind.org) + diff --git a/Makefile b/Makefile index 38bdab5c..58a44fb8 100644 --- a/Makefile +++ b/Makefile @@ -170,8 +170,13 @@ MAINSRCS := physfs.c archivers/dir.c ifeq ($(strip $(use_archive_zip)),true) MAINSRCS += archivers/zip.c archivers/unzip.c CFLAGS += -DPHYSFS_SUPPORTS_ZIP +ifeq ($(strip $(cygwin)),true) +CFLAGS += -Izlibwin32 +LDFLAGS += zlibwin32/zlibstat.lib +else LDFLAGS += -lz endif +endif ifeq ($(strip $(use_archive_grp)),true) MAINSRCS += archivers/grp.c diff --git a/archivers/zip.c b/archivers/zip.c index 51759386..be812c35 100644 --- a/archivers/zip.c +++ b/archivers/zip.c @@ -363,7 +363,7 @@ static LinkedStringList *ZIP_enumerateFiles(DirHandle *h, int omitSymLinks) { ZIPinfo *zi = (ZIPinfo *) (h->opaque); - int i; + unsigned int i; int dlen; LinkedStringList *retval = NULL; LinkedStringList *l = NULL; @@ -470,7 +470,7 @@ static int ZIP_exists_symcheck(DirHandle *h, const char *name, int follow) ZIPinfo *zi = (ZIPinfo *) (h->opaque); int dlen; char *d; - int i; + unsigned int i; ZIPentry *entry; dlen = strlen(name); diff --git a/platform/win32.c b/platform/win32.c index c4bac85b..9da2e17f 100644 --- a/platform/win32.c +++ b/platform/win32.c @@ -1,5 +1,5 @@ /* - * Unix support routines for PhysicsFS. + * Win32 support routines for PhysicsFS. * * Please see the file LICENSE in the source's root directory. * @@ -12,18 +12,7 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + #define __PHYSICSFS_INTERNAL__ #include "physfs_internal.h" @@ -34,20 +23,20 @@ const char *__PHYSFS_platformDirSeparator = "\\"; static const char *win32strerror(void) { - static char msgbuf[255]; + static TCHAR msgbuf[255]; FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - &msgbuf, - 0, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ + msgbuf, + sizeof (msgbuf) / sizeof (TCHAR), NULL ); - return(msgbuf); + return((const char *) msgbuf); } /* win32strerror */ @@ -56,7 +45,6 @@ char **__PHYSFS_platformDetectAvailableCDs(void) char **retval = (char **) malloc(sizeof (char *)); int cd_count = 1; /* We count the NULL entry. */ char drive_str[4] = "x:\\"; - int i; for (drive_str[0] = 'A'; drive_str[0] <= 'Z'; drive_str[0]++) { @@ -81,22 +69,6 @@ char **__PHYSFS_platformDetectAvailableCDs(void) } /* __PHYSFS_detectAvailableCDs */ -static char *copyEnvironmentVariable(const char *varname) -{ - const char *envr = getenv(varname); - char *retval = NULL; - - if (envr != NULL) - { - retval = malloc(strlen(envr) + 1); - if (retval != NULL) - strcpy(retval, envr); - } /* if */ - - return(retval); -} /* copyEnvironmentVariable */ - - char *__PHYSFS_platformCalcBaseDir(const char *argv0) { DWORD buflen = 0; @@ -106,17 +78,17 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) if (strchr(argv0, '\\') != NULL) /* default behaviour can handle this. */ return(NULL); - SearchPath(NULL, argv0, NULL, &buflen, NULL, NULL); + buflen = SearchPath(NULL, argv0, NULL, buflen, NULL, NULL); retval = (char *) malloc(buflen); BAIL_IF_MACRO(!retval, ERR_OUT_OF_MEMORY, NULL); - SearchPath(NULL, argv0, NULL, &buflen, retval, &filepart); + SearchPath(NULL, argv0, NULL, buflen, retval, &filepart); return(retval); } /* __PHYSFS_platformCalcBaseDir */ char *__PHYSFS_platformGetUserName(void) { - LPDWORD bufsize = 0; + DWORD bufsize = 0; LPTSTR retval = NULL; if (GetUserName(NULL, &bufsize) == 0) /* This SHOULD fail. */ @@ -146,9 +118,24 @@ int __PHYSFS_platformGetThreadID(void) } /* __PHYSFS_platformGetThreadID */ +/* ...make this Cygwin AND Visual C friendly... */ int __PHYSFS_platformStricmp(const char *x, const char *y) { - return(stricmp(x, y)); + int ux, uy; + + do + { + ux = toupper((int) *x); + uy = toupper((int) *y); + if (ux > uy) + return(1); + else if (ux < uy) + return(-1); + x++; + y++; + } while ((ux) && (uy)); + + return(0); } /* __PHYSFS_platformStricmp */ @@ -178,6 +165,7 @@ char *__PHYSFS_platformCvtToDependent(const char *prepend, ((append) ? strlen(append) : 0) + strlen(dirName) + 1; char *retval = malloc(len); + char *p; BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); @@ -217,7 +205,7 @@ LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname, dir = FindFirstFile(dirname, &ent); BAIL_IF_MACRO(dir == INVALID_HANDLE_VALUE, win32strerror(), NULL); - for (; FineNextFile(dir, &ent) != 0; ) + for (; FindNextFile(dir, &ent) != 0; ) { if (strcmp(ent.cFileName, ".") == 0) continue; @@ -267,25 +255,26 @@ int __PHYSFS_platformFileLength(FILE *handle) char *__PHYSFS_platformCurrentDir(void) { - LPTSTR *retval; + LPTSTR retval; DWORD buflen = 0; - GetCurrentDirectory(&buflen, NULL); + buflen = GetCurrentDirectory(buflen, NULL); retval = (LPTSTR) malloc(buflen); - GetCurrentDirectory(&buflen, retval); + GetCurrentDirectory(buflen, retval); return((char *) retval); } /* __PHYSFS_platformCurrentDir */ char *__PHYSFS_platformRealPath(const char *path) { + /* !!! FIXME: This isn't supported on CygWin! */ return(_fullpath(NULL, path, _MAX_PATH)); } /* __PHYSFS_platformRealPath */ int __PHYSFS_platformMkDir(const char *path) { - rc = CreateDirectory(path, NULL); + DWORD rc = CreateDirectory(path, NULL); BAIL_IF_MACRO(rc == 0, win32strerror(), 0); return(1); } /* __PHYSFS_platformMkDir */