Module neither: Change committed

coderjoe at icculus.org coderjoe at icculus.org
Sun Mar 28 08:35:13 EST 2004


Commiter   : coderjoe
CVSROOT    : /cvs/cvsroot/neither
Module     : neither
Commit time: 2004-03-28 13:35:13 UTC

Log message:

fix up fs/dir_win32.c
update msvc6 projects.

Modified files:
     darkwar/darkwar.dsw darkwar/fs/dir_win32.c

Added files:
     darkwar/fs/fs.dsp

------=MIME.59ecbb129a9e3fca80d85d5fe1429ca4
Content-Type: text/plain; name="neither.20040328.133513.coderjoe.diff"
Content-Disposition: attachment; filename="neither.20040328.133513.coderjoe.diff"
Content-Transfer-Encoding: 8bit

Index: neither/darkwar/darkwar.dsw
diff -u neither/darkwar/darkwar.dsw:1.4 neither/darkwar/darkwar.dsw:1.5
--- neither/darkwar/darkwar.dsw:1.4	Sat Mar 27 12:40:57 2004
+++ neither/darkwar/darkwar.dsw	Sun Mar 28 08:35:03 2004
@@ -3,7 +3,7 @@
 
 ###############################################################################
 
-Project: "darkwar"=".\darkwar.dsp" - Package Owner=<4>
+Project: "darkwar"=.\darkwar.dsp - Package Owner=<4>
 
 Package=<5>
 {{{
@@ -17,11 +17,26 @@
     Begin Project Dependency
     Project_Dep_Name game
     End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name fs
+    End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "fs"=.\fs\fs.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
 }}}
 
 ###############################################################################
 
-Project: "game"=".\game\game.dsp" - Package Owner=<4>
+Project: "game"=.\game\game.dsp - Package Owner=<4>
 
 Package=<5>
 {{{
@@ -33,7 +48,7 @@
 
 ###############################################################################
 
-Project: "renderer"=".\renderer\renderer.dsp" - Package Owner=<4>
+Project: "renderer"=.\renderer\renderer.dsp - Package Owner=<4>
 
 Package=<5>
 {{{
Index: neither/darkwar/fs/dir_win32.c
diff -u neither/darkwar/fs/dir_win32.c:1.1 neither/darkwar/fs/dir_win32.c:1.2
--- neither/darkwar/fs/dir_win32.c:1.1	Sat Mar 27 15:57:41 2004
+++ neither/darkwar/fs/dir_win32.c	Sun Mar 28 08:35:03 2004
@@ -23,118 +23,242 @@
 */
 
 static const char rcsid[] =
-	"$Id: dir_win32.c,v 1.1 2004/03/27 20:57:41 warp Exp $";
+	"$Id: dir_win32.c,v 1.2 2004/03/28 13:35:03 coderjoe Exp $";
 
-#include "twiconfig.h"
+#include "dwconfig.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <string.h>
 #include <io.h>
 	
-#include "common.h"
-#include "strlib.h"
-#include "qtypes.h"
-#include "fs.h"
-#include "fs_hash.h"
-#include "dir.h"
+#include "ncommon.h"
+#include "nconsole.h"
+#include "nstring.h"
+#include "ntypes.h"
+#include "fs/fs.h"
+#include "fs/dir.h"
 
 typedef struct fsd_group_s {
-	char *path;
+	char	*path;
+	NUint	seq;
 } fsd_group_t;
 
+typedef struct fsd_file_s {
+	char	*path;
+	NUint	last_seen;
+	time_t	mtime;
+} fsd_file_t;
+
 static void
 FSD_Free (fs_group_t *group)
 {
-	Zone_Free (group->fs_data);
+	Mem_Free (group->fs_data);
 }
 
 static void
 FSD_Free_File (fs_file_t *file)
 {
-	Zone_Free (file->name_base);
+	fsd_file_t	*f = file->fs_data;
+
+	Mem_Free (f->path);
+	Mem_Free (f);
+	Mem_Free (file->h.name);
 }
 
 static SDL_RWops *
 FSD_Open_File (fs_file_t *file, Uint32 flags)
 {
-	fsd_group_t	*dir;
-	char		*name;
+	fsd_file_t	*f = file->fs_data;
 	SDL_RWops	*rw;
 
-	dir = file->group->fs_data;
-	if (file->ext)
-		name = zasprintf (tempzone, "%s/%s.%s", dir->path, file->name_base, file->ext);
-	else
-		name = zasprintf (tempzone, "%s/%s", dir->path, file->name_base);
-
-	if (flags & FSF_WRITE) {
-		if (file->group->flags & FS_READ_ONLY) {
-			Com_Printf ("Refusing to open '%s' in write mode.\n", name);
+	if (flags & FSO_WRITE) {
+		if (file->group->flags & FSG_READ_ONLY) {
+			Console_Printf ("Refusing to open '%s' in write mode.\n", f->path);
 			rw = NULL;
 		} else
-			rw = SDL_RWFromFile (name, (flags & FSF_ASCII) ? "w" : "wb");
+			rw = SDL_RWFromFile (f->path, (flags & FSO_ASCII) ? "w" : "wb");
 	} else
-		rw = SDL_RWFromFile (name, (flags & FSF_ASCII) ? "r" : "rb");
+		rw = SDL_RWFromFile (f->path, (flags & FSO_ASCII) ? "r" : "rb");
 
-	Zone_Free (name);
 	return rw;
 }
 
 static void
-FSD_Add_Dir (fs_group_t *group, fsd_group_t *g_dir, char *path, int depth)
+FSD_Add_File (fs_group_t *group, fsd_group_t *g_dir, struct _finddata_t *n_file, char *name, char *path)
+{
+	fsd_file_t	*f;
+
+	f = Mem_Alloc (fs_zone, sizeof (fsd_file_t));
+	String_Set (&f->path, fs_zone, path);
+	f->last_seen = g_dir->seq;
+	f->mtime = n_file->time_write;
+
+	FS_Add_File (group, name, n_file->size, FSD_Open_File, f, 0);
+}
+
+static void
+FSD_Purge_Old (fs_group_t *group)
+{
+	fsd_group_t		*dgroup = (fsd_group_t *) group->fs_data;
+	fs_file_t		*file;
+	fsd_file_t		*dfile;
+	hash_value_t	*val, *next;
+	NUint			i;
+
+	for (i = 0; i < group->files->length; i++) {
+		val = group->files->values[i];
+		while (val) {
+			next = val->next;
+			file = (fs_file_t *) val->data;
+			dfile = (fsd_file_t *) file->fs_data;
+			if (dfile->last_seen != dgroup->seq)
+				hash_del (group->files, val->data);
+			val = next;
+		}
+	}
+}
+
+static void
+FSD_Reload_Dir (fs_group_t *group, fsd_group_t *g_dir, char *path, int depth)
 {
 	long int			dir;
 	struct _finddata_t	n_file;
-	char				*file, *tmp;
+	char				file_id[512], full_path[512], f_path[512], *tmp;
+	fs_file_t		*file;
+	hash_data_t		search;
 
 	if (depth > 32)
 		return;
 
-	tmp = zasprintf(fs_zone, "%s/%s/*", g_dir->path, path);
+	if (path)
+		snprintf (full_path, sizeof (full_path), "%s/%s/", g_dir->path, path);
+	else
+		snprintf (full_path, sizeof (full_path), "%s/", g_dir->path);
+
+	tmp = String_APrintf (fs_zone, "%s*", full_path);
 	dir = _findfirst (tmp, &n_file);
+	Mem_Free (tmp);
+
+//	Com_DFPrintf (DEBUG_FS, "Posix Add Dir: %s %p\n", full_path, dir);
+	if (dir!=-1) {
+		g_dir->seq++;
+		goto fire;
+	}
+	Console_Printf("FSD_Add_Dir: Unable to open %s. (%s)\n", full_path, strerror(errno));
+	Mem_Free (full_path);
+	return;
 
-	Com_DFPrintf (DEBUG_FS, "Win32 Add Dir: %s %p\n", tmp, dir);
+	while (!_findnext(dir, &n_file)) {
+fire:
+		if (!strcmp(".", n_file.name) || !strcmp("..", n_file.name))
+			continue;
+
+		snprintf (f_path, sizeof(f_path), "%s/%s", full_path, n_file.name);
 
-	Zone_Free (tmp);
-	if (dir != -1)
+		if (path)
+			search.name_len = snprintf (file_id, sizeof (file_id), "%s/%s", path, n_file.name) + 1;
+		else
+			search.name_len = snprintf (file_id, sizeof (file_id), "%s", n_file.name) + 1;
+		search.name = file_id;
+		if (n_file.attrib & _A_SUBDIR)
+			FSD_Reload_Dir (group, g_dir, file_id, depth + 1);
+		else {
+			file = (fs_file_t *) hash_get (group->files, &search);
+			if (!file)
+				FSD_Add_File (group, g_dir, &n_file, file_id, f_path);
+			else {
+				fsd_file_t	*f = (fsd_file_t *) file->fs_data;
+
+				if ((file->len != (size_t) n_file.size) ||
+						(f->mtime != n_file.time_write)) {
+					hash_del (group->files, &file->h);
+					FSD_Add_File (group, g_dir, &n_file, file_id, f_path);
+				} else
+					f->last_seen = g_dir->seq;
+			}
+		}
+	}
+	_findclose (dir);
+	Mem_Free (full_path);
+	FSD_Purge_Old (group);
+}
+
+static void
+FSD_Add_Dir (fs_group_t *group, fsd_group_t *g_dir, char *path, int depth)
+{
+	char				*file, *full_path, *tmp, *f_path;
+	struct _finddata_t	n_file;
+	long int			dir;
+
+	if (depth > 32)
+		return;
+
+	if (path)
+		full_path = String_APrintf (fs_zone, "%s/%s/", g_dir->path, path);
+	else
+		full_path = String_APrintf (fs_zone, "%s/", g_dir->path);
+
+	tmp = String_APrintf (fs_zone, "%s*", full_path);
+	dir = _findfirst (tmp, &n_file);
+	Mem_Free (tmp);
+
+//	Com_DFPrintf (DEBUG_FS, "Win32 Add Dir: %s %p\n", full_path, dir);
+	if (dir != -1) {
+		g_dir->seq++;
 		goto fire;
+	}
 
+	Console_Printf("FSD_Add_Dir: Unable to open %s. (%s)\n", full_path, strerror(errno));
+	Mem_Free (full_path);
 	return;
 
-	while (!_findnext (dir, &n_file)) {
+	while (!_findnext(dir, &n_file)) {
 fire:
 		if (!strcmp(".", n_file.name) || !strcmp("..", n_file.name))
 			continue;
-		file = zasprintf(fs_zone, "%s/%s", path, n_file.name);
+
+		f_path = String_APrintf (fs_zone, "%s/%s", full_path, n_file.name);
+
+		if (path)
+			file = String_APrintf(fs_zone, "%s/%s", path, n_file.name);
+		else
+			file = String_APrintf(fs_zone, "%s", n_file.name);
+
 		if (n_file.attrib & _A_SUBDIR)
 			FSD_Add_Dir (group, g_dir, file, depth + 1);
 		else
-			FS_Add_File (group, file, n_file.size, FSD_Open_File, NULL);
-		Zone_Free (file);
+			FSD_Add_File (group, g_dir, &n_file, file, f_path);
+		Mem_Free (file);
+		Mem_Free (f_path);
 	}
 	_findclose (dir);
+	Mem_Free (full_path);
 }
 
-qboolean
+Nbool
 FSD_Open_New (fs_group_t *group, fs_new_t *new)
 {
 	fsd_group_t	*dir = group->fs_data;
-	char		*name;
+	FILE		*file;
+	char		*tmp;
 
-	new->temp = zasprintf (fs_zone, "%s.tmp", new->wanted);
-	name = zasprintf (tempzone, "%s/%s", dir->path, new->temp);
-	new->rw = SDL_RWFromFile (name, (new->flags & FSF_ASCII) ? "w" : "wb");
-	if (!new->rw) {
-		Com_Printf ("FSD_Open_New: Unable to open %s. (%s) (%s)\n", name, strerror(errno), SDL_GetError());
-		Zone_Free (new->temp);
-		Zone_Free (name);
+	new->temp = String_APrintf (fs_zone, "%s.tmp", new->wanted);
+	tmp = String_APrintf(fs_zone, "%s/%s", dir->path, new->temp);
+	if (!(file = fopen(tmp, (new->flags & FSO_ASCII) ? "w" : "wb"))) {
+		Console_Printf ("FSD_Open_New: Unable to fdopen. %s\n", strerror(errno));
+		Mem_Free (new->temp);
+		Mem_Free (tmp);
+		new->temp = NULL;
 		return false;
-	} else {
-		Zone_Free (name);
-		return true;
 	}
+	Mem_Free (tmp);
+	if ((new->rw = SDL_RWFromFP (file, 1)))
+		return true;
+	else
+		return false;
 }
 
 void
@@ -142,15 +266,19 @@
 {
 	fsd_group_t	*dir = group->fs_data;
 	int			len;
+	char		*t0, *t1;
 
 	SDL_RWseek (new->rw, 0, SEEK_END);
 	len = SDL_RWtell (new->rw);
 	SDL_RWclose (new->rw);
-	rename (va("%s/%s", dir->path, new->temp),
-			va("%s/%s", dir->path, new->wanted));
-	Zone_Free (new->temp);
+	t0 = String_APrintf (fs_zone, "%s/%s", dir->path, new->temp);
+	t1 = String_APrintf (fs_zone, "%s/%s", dir->path, new->wanted);
+	rename (t0, t1);
+	Mem_Free (new->temp);
+	Mem_Free (t0);
+	Mem_Free (t1);
 	new->temp = NULL;
-	FS_Add_File (group, new->wanted, len, FSD_Open_File, NULL);
+	FS_Add_File (group, new->wanted, len, FSD_Open_File, NULL, 0);
 }
 
 fs_group_t *
@@ -161,21 +289,21 @@
 	fsd_group_t	*dir;
 
 	group = FS_Alloc_Group (parent, id);
-	dir = Zone_Alloc (fs_zone, sizeof (fsd_group_t));
+	dir = Mem_Alloc (fs_zone, sizeof (fsd_group_t));
 	group->fs_data = dir;
 	group->free = FSD_Free;
 	group->free_file = FSD_Free_File;
 	group->flags |= flags;
 	if (parent)
 		group->flags |= parent->flags;
-	if (!(group->flags & FS_READ_ONLY)) {
+	if (!(group->flags & FSG_READ_ONLY)) {
 		group->open_new = FSD_Open_New;
 		group->close_new = FSD_Close_New;
 	}
 
-	dir->path = Zstrdup (fs_zone, path);
+	String_Set (&dir->path, fs_zone, path);
 
-	FSD_Add_Dir (group, dir, "", 0);
+	FSD_Add_Dir (group, dir, NULL, 0);
 
 	return group;
 }
Index: neither/darkwar/fs/fs.dsp
diff -u /dev/null neither/darkwar/fs/fs.dsp:1.1
--- /dev/null	Sun Mar 28 08:35:13 2004
+++ neither/darkwar/fs/fs.dsp	Sun Mar 28 08:35:03 2004
@@ -0,0 +1,132 @@
+# Microsoft Developer Studio Project File - Name="fs" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=fs - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "fs.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "fs.mak" CFG="fs - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "fs - Win32 Release" (based on "Win32 (x86) Static Library")
+!MESSAGE "fs - Win32 Debug" (based on "Win32 (x86) Static Library")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "fs - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD CPP /nologo /G5 /MD /W3 /GX /O2 /I ".." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF  "$(CFG)" == "fs - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
+# ADD CPP /nologo /G5 /MD /W3 /Gm /GX /ZI /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ENDIF 
+
+# Begin Target
+
+# Name "fs - Win32 Release"
+# Name "fs - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\dir_win32.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\fs.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\fs_new.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\pak.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\rw_ops.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\dir.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\fs.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\fs_new.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\pak.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\rw_ops.h
+# End Source File
+# End Group
+# End Target
+# End Project


More information about the neither-commits mailing list