]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - fs.c
Added a "log_file" cvar to control the log file name (default: "" which means no...
[xonotic/darkplaces.git] / fs.c
diff --git a/fs.c b/fs.c
index 90ba0702bd5b88a617d8ca6dfdc8f7dfe4091287..3ecac6915545f12baeb1533bfc9172d30d9c7cce 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -262,7 +262,7 @@ int fs_filesize;
 
 pack_t *packlist = NULL;
 
-searchpath_t *fs_searchpaths;
+searchpath_t *fs_searchpaths = NULL;
 
 #define MAX_FILES_IN_PACK      65536
 
@@ -868,7 +868,7 @@ char *FS_FileExtension (const char *in)
                separator = backslash;
        if (separator < colon)
                separator = colon;
-       if (dot < separator)
+       if (dot == NULL || dot < separator)
                return "";
        dot++;
        for (i = 0;i < 7 && dot[i];i++)
@@ -896,6 +896,7 @@ void FS_Init (void)
        Cmd_AddCommand ("ls", FS_Ls_f);
 
        strcpy(fs_basedir, ".");
+       strcpy(fs_gamedir, ".");
 
        PK3_OpenLibrary ();
 
@@ -903,30 +904,11 @@ void FS_Init (void)
        // Overrides the system supplied base directory (under GAMENAME)
        i = COM_CheckParm ("-basedir");
        if (i && i < com_argc-1)
-               strlcpy (fs_basedir, com_argv[i+1], sizeof (fs_basedir));
-
-       i = strlen (fs_basedir);
-       if (i > 0 && (fs_basedir[i-1] == '\\' || fs_basedir[i-1] == '/'))
-               fs_basedir[i-1] = 0;
-
-       // start up with GAMENAME by default (id1)
-       strlcpy (com_modname, GAMENAME, sizeof (com_modname));
-       FS_AddGameDirectory (va("%s/"GAMENAME, fs_basedir));
-       if (gamedirname[0])
        {
-               fs_modified = true;
-               strlcpy (com_modname, gamedirname, sizeof (com_modname));
-               FS_AddGameDirectory (va("%s/%s", fs_basedir, gamedirname));
-       }
-
-       // -game <gamedir>
-       // Adds basedir/gamedir as an override game
-       i = COM_CheckParm ("-game");
-       if (i && i < com_argc-1)
-       {
-               fs_modified = true;
-               strlcpy (com_modname, com_argv[i+1], sizeof (com_modname));
-               FS_AddGameDirectory (va("%s/%s", fs_basedir, com_argv[i+1]));
+               strlcpy (fs_basedir, com_argv[i+1], sizeof (fs_basedir));
+               i = strlen (fs_basedir);
+               if (i > 0 && (fs_basedir[i-1] == '\\' || fs_basedir[i-1] == '/'))
+                       fs_basedir[i-1] = 0;
        }
 
        // -path <dir or packfile> [<dir or packfile>] ...
@@ -935,7 +917,6 @@ void FS_Init (void)
        if (i)
        {
                fs_modified = true;
-               fs_searchpaths = NULL;
                while (++i < com_argc)
                {
                        if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-')
@@ -959,6 +940,29 @@ void FS_Init (void)
                        search->next = fs_searchpaths;
                        fs_searchpaths = search;
                }
+               return;
+       }
+
+       // start up with GAMENAME by default (id1)
+       strlcpy (com_modname, GAMENAME, sizeof (com_modname));
+       FS_AddGameDirectory (va("%s/"GAMENAME, fs_basedir));
+
+       // add the game-specific path, if any
+       if (gamedirname[0])
+       {
+               fs_modified = true;
+               strlcpy (com_modname, gamedirname, sizeof (com_modname));
+               FS_AddGameDirectory (va("%s/%s", fs_basedir, gamedirname));
+       }
+
+       // -game <gamedir>
+       // Adds basedir/gamedir as an override game
+       i = COM_CheckParm ("-game");
+       if (i && i < com_argc-1)
+       {
+               fs_modified = true;
+               strlcpy (com_modname, com_argv[i+1], sizeof (com_modname));
+               FS_AddGameDirectory (va("%s/%s", fs_basedir, com_argv[i+1]));
        }
 }
 
@@ -1445,6 +1449,19 @@ int FS_Printf(qfile_t* file, const char* format, ...)
 }
 
 
+/*
+====================
+FS_VPrintf
+
+Print a string into a file
+====================
+*/
+int FS_VPrintf(qfile_t* file, const char* format, va_list ap)
+{
+       return vfprintf (file->stream, format, ap);
+}
+
+
 /*
 ====================
 FS_Getc
@@ -1900,7 +1917,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
        if (separator < colon)
                separator = colon;
        basepathlength = separator - pattern;
-       basepath = Z_Malloc(basepathlength + 1);
+       basepath = Mem_Alloc (tempmempool, basepathlength + 1);
        if (basepathlength)
                memcpy(basepath, pattern, basepathlength);
        basepath[basepathlength] = 0;
@@ -2004,7 +2021,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
                        stringlistfree(liststart);
        }
 
-       Z_Free(basepath);
+       Mem_Free(basepath);
        return search;
 }
 
@@ -2025,7 +2042,7 @@ int FS_ListDirectory(const char *pattern, int oneperline)
        const char *name;
        char linebuf[4096];
        fssearch_t *search;
-       search = FS_Search(pattern, true, false);
+       search = FS_Search(pattern, true, true);
        if (!search)
                return 0;
        numfiles = search->numfilenames;