]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/path_init.c
radiant/q3map2: add option to disable engine path and home path
[xonotic/netradiant.git] / tools / quake3 / q3map2 / path_init.c
index e90b382da4c03e7180e667dc5fa6627881a8ded4..0520d33277e1d3db414580fa733de4f9b087cf4b 100644 (file)
-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
-\r
-----------------------------------------------------------------------------------\r
-\r
-This code has been altered significantly from its original form, to support\r
-several games based on the Quake III Arena engine, in the form of "Q3Map2."\r
-\r
-------------------------------------------------------------------------------- */\r
-\r
-\r
-\r
-/* marker */\r
-#define PATH_INIT_C\r
-\r
-\r
-\r
-/* dependencies */\r
-#include "q3map2.h"\r
-\r
-\r
-\r
-/* path support */\r
-#define MAX_BASE_PATHS 10\r
-#define MAX_GAME_PATHS 10\r
-\r
-char                                   *homePath;\r
-char                                   installPath[ MAX_OS_PATH ];\r
-\r
-int                                            numBasePaths;\r
-char                                   *basePaths[ MAX_BASE_PATHS ];\r
-int                                            numGamePaths;\r
-char                                   *gamePaths[ MAX_GAME_PATHS ];\r
-\r
-\r
-\r
-/*\r
-some of this code is based off the original q3map port from loki\r
-and finds various paths. moved here from bsp.c for clarity.\r
-*/\r
-\r
-/*\r
-PathLokiGetHomeDir()\r
-gets the user's home dir (for ~/.q3a)\r
-*/\r
-\r
-char *LokiGetHomeDir( void )\r
-{\r
-       #ifndef Q_UNIX\r
-               return NULL;\r
-       #else\r
-               char                    *home;\r
-               uid_t                   id;\r
-               struct passwd   *pwd;\r
-               \r
-               \r
-               /* get the home environment variable */\r
-               home = getenv( "HOME" );\r
-               if( home == NULL )\r
-               {\r
-                       /* do some more digging */\r
-                       id = getuid();\r
-                       setpwent();\r
-                       while( (pwd = getpwent()) != NULL )\r
-                       {\r
-                               if( pwd->pw_uid == id )\r
-                               {\r
-                                       home = pwd->pw_dir;\r
-                                       break;\r
-                               }\r
-                       }\r
-                       endpwent();\r
-               }\r
-               \r
-               /* return it */\r
-               return home;\r
-       #endif\r
-}\r
-\r
-\r
-\r
-/*\r
-PathLokiInitPaths()\r
-initializes some paths on linux/os x\r
-*/\r
-\r
-void LokiInitPaths( char *argv0 )\r
-{\r
-       #ifndef Q_UNIX\r
-               /* this is kinda crap, but hey */\r
-               strcpy( installPath, "../" );\r
-       #else\r
-               char            temp[ MAX_OS_PATH ];\r
-               char            *home;\r
-               char            *path;\r
-               char            *last;\r
-               qboolean        found;\r
-               \r
-               \r
-               /* get home dir */\r
-               home = LokiGetHomeDir();\r
-               if( home == NULL )\r
-                       home = ".";\r
-               \r
-               /* do some path divining */\r
-               strcpy( temp, argv0 );\r
-               if( strrchr( temp, '/' ) )\r
-                       argv0 = strrchr( argv0, '/' ) + 1;\r
-               else\r
-               {\r
-                       /* get path environment variable */\r
-                       path = getenv( "PATH" );\r
-                       \r
-                       /* minor setup */\r
-                       last[ 0 ] = path[ 0 ];\r
-                       last[ 1 ] = '\0';\r
-                       found = qfalse;\r
-                       \r
-                       /* go through each : segment of path */\r
-                       while( last[ 0 ] != '\0' && found == qfalse )\r
-                       {\r
-                               /* null out temp */\r
-                               temp[ 0 ] = '\0';\r
-                               \r
-                               /* find next chunk */\r
-                               last = strchr( path, ':' );\r
-                               if( last == NULL )\r
-                                       last = path + strlen( path );\r
-                               \r
-                               /* found home dir candidate */\r
-                               if( *path == '~' )\r
-                               {\r
-                                       strcpy( temp, home );\r
-                                       path++;\r
-                               }\r
-                               \r
-                               /* concatenate */\r
-                               if( last > (path + 1) )\r
-                               {\r
-                                       strncat( temp, path, (last - path) );\r
-                                       strcat( temp, "/" );\r
-                               }\r
-                               strcat( temp, "./" );\r
-                               strcat( temp, argv0 );\r
-                               \r
-                               /* verify the path */\r
-                               if( access( temp, X_OK ) == 0 )\r
-                                       found++;\r
-                               path = last + 1;\r
-                       }\r
-               }\r
-               \r
-               /* flake */\r
-               if( realpath( temp, installPath ) )\r
-               {\r
-                       /* q3map is in "tools/" */\r
-                       *(strrchr( installPath, '/' )) = '\0';\r
-                       *(strrchr( installPath, '/' ) + 1) = '\0';\r
-               }\r
-               \r
-               /* set home path */\r
-               homePath = home;\r
-       #endif\r
-}\r
-\r
-\r
-\r
-/*\r
-CleanPath() - ydnar\r
-cleans a dos path \ -> /\r
-*/\r
-\r
-void CleanPath( char *path )\r
-{\r
-       while( *path )\r
-       {\r
-               if( *path == '\\' )\r
-                       *path = '/';\r
-               path++;\r
-       }\r
-}\r
-\r
-\r
-\r
-/*\r
-SetGame() - ydnar\r
-sets the game based on a -game argument\r
-doesn't set it if the game doesn't match any known games\r
-*/\r
-\r
-void SetGame( char *arg )\r
-{\r
-       int     i;\r
-       \r
-       \r
-       /* dummy check */\r
-       if( arg == NULL || arg[ 0 ] == '\0' )\r
-               return;\r
-       \r
-       /* joke */\r
-       if( !Q_stricmp( arg, "quake1" ) ||\r
-               !Q_stricmp( arg, "quake2" ) ||\r
-               !Q_stricmp( arg, "unreal" ) ||\r
-               !Q_stricmp( arg, "ut2k3" ) ||\r
-               !Q_stricmp( arg, "dn3d" ) ||\r
-               !Q_stricmp( arg, "dnf" ) ||\r
-               !Q_stricmp( arg, "hl" ) )\r
-       {\r
-               Sys_Printf( "April fools, silly rabbit!\n" );\r
-               exit( 0 );\r
-       }\r
-       \r
-       /* test it */\r
-       i = 0;\r
-       while( games[ i ].arg != NULL )\r
-       {\r
-               if( Q_stricmp( arg, games[ i ].arg ) == 0 )\r
-                       game = &games[ i ];\r
-               i++;\r
-       }\r
-}\r
-\r
-\r
-\r
-/*\r
-AddBasePath() - ydnar\r
-adds a base path to the list\r
-*/\r
-\r
-void AddBasePath( char *path )\r
-{\r
-       /* dummy check */\r
-       if( path == NULL || path[ 0 ] == '\0' || numBasePaths >= MAX_BASE_PATHS )\r
-               return;\r
-       \r
-       /* add it to the list */\r
-       basePaths[ numBasePaths ] = safe_malloc( strlen( path ) + 1 );\r
-       strcpy( basePaths[ numBasePaths ], path );\r
-       CleanPath( basePaths[ numBasePaths ] );\r
-       numBasePaths++;\r
-}\r
-\r
-\r
-\r
-/*\r
-AddHomeBasePath() - ydnar\r
-adds a base path to the beginning of the list, prefixed by ~/\r
-*/\r
-\r
-void AddHomeBasePath( char *path )\r
-{\r
-       #ifdef Q_UNIX\r
-               int             i;\r
-               char    temp[ MAX_OS_PATH ];\r
-               \r
-               \r
-               /* dummy check */\r
-               if( path == NULL || path[ 0 ] == '\0' )\r
-                       return;\r
-\r
-               /* make a hole */\r
-               for( i = 0; i < (MAX_BASE_PATHS - 1); i++ )\r
-                       basePaths[ i + 1 ] = basePaths[ i ];\r
-               \r
-               /* concatenate home dir and path */\r
-               sprintf( temp, "%s/%s", homePath, path );\r
-               \r
-               /* add it to the list */\r
-               basePaths[ 0 ] = safe_malloc( strlen( temp ) + 1 );\r
-               strcpy( basePaths[ 0 ], temp );\r
-               CleanPath( basePaths[ 0 ] );\r
-               numBasePaths++;\r
-       #endif\r
-}\r
-\r
-\r
-\r
-/*\r
-AddGamePath() - ydnar\r
-adds a game path to the list\r
-*/\r
-\r
-void AddGamePath( char *path )\r
-{\r
-       /* dummy check */\r
-       if( path == NULL || path[ 0 ] == '\0' || numGamePaths >= MAX_GAME_PATHS )\r
-               return;\r
-       \r
-       /* add it to the list */\r
-       gamePaths[ numGamePaths ] = safe_malloc( strlen( path ) + 1 );\r
-       strcpy( gamePaths[ numGamePaths ], path );\r
-       CleanPath( gamePaths[ numGamePaths ] );\r
-       numGamePaths++;\r
-}\r
-\r
-\r
-\r
-\r
-/*\r
-InitPaths() - ydnar\r
-cleaned up some of the path initialization code from bsp.c\r
-will remove any arguments it uses\r
-*/\r
-\r
-void InitPaths( int *argc, char **argv )\r
-{\r
-       int             i, j, k, len, len2;\r
-       char    temp[ MAX_OS_PATH ];\r
-       \r
-       \r
-       /* note it */\r
-       Sys_FPrintf( SYS_VRB, "--- InitPaths ---\n" );\r
-       \r
-       /* get the install path for backup */\r
-       LokiInitPaths( argv[ 0 ] );\r
-       \r
-       /* set game to default (q3a) */\r
-       game = &games[ 0 ];\r
-       numBasePaths = 0;\r
-       numGamePaths = 0;\r
-       \r
-       /* parse through the arguments and extract those relevant to paths */\r
-       for( i = 0; i < *argc; i++ )\r
-       {\r
-               /* check for null */\r
-               if( argv[ i ] == NULL )\r
-                       continue;\r
-               \r
-               /* -game */\r
-               if( strcmp( argv[ i ], "-game" ) == 0 )\r
-               {\r
-                       if( ++i >= *argc )\r
-                               Error( "Out of arguments: No game specified after %s", argv[ i - 1 ] );\r
-                       argv[ i - 1 ] = NULL;\r
-                       SetGame( argv[ i ] );\r
-                       argv[ i ] = NULL;\r
-               }\r
-\r
-               /* -fs_basepath */\r
-               else if( strcmp( argv[ i ], "-fs_basepath" ) == 0 )\r
-               {\r
-                       if( ++i >= *argc )\r
-                               Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );\r
-                       argv[ i - 1 ] = NULL;\r
-                       AddBasePath( argv[ i ] );\r
-                       argv[ i ] = NULL;\r
-               }\r
-               \r
-               /* -fs_game */\r
-               else if( strcmp( argv[ i ], "-fs_game" ) == 0 )\r
-               {\r
-                       if( ++i >= *argc )\r
-                               Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );\r
-                       argv[ i - 1 ] = NULL;\r
-                       AddGamePath( argv[ i ] );\r
-                       argv[ i ] = NULL;\r
-               }\r
-       }\r
-       \r
-       /* remove processed arguments */\r
-       for( i = 0, j = 0, k = 0; i < *argc && j < *argc; i++, j++ )\r
-       {\r
-               for( j; j < *argc && argv[ j ] == NULL; j++ );\r
-               argv[ i ] = argv[ j ];\r
-               if( argv[ i ] != NULL )\r
-                       k++;\r
-       }\r
-       *argc = k;\r
-       \r
-       /* add standard game path */\r
-       AddGamePath( game->gamePath );\r
-       \r
-       /* if there is no base path set, figure it out */\r
-       if( numBasePaths == 0 )\r
-       {\r
-               /* this is another crappy replacement for SetQdirFromPath() */\r
-               len2 = strlen( game->magic );\r
-               for( i = 0; i < *argc && numBasePaths == 0; i++ )\r
-               {\r
-                       /* extract the arg */\r
-                       strcpy( temp, argv[ i ] );\r
-                       CleanPath( temp );\r
-                       len = strlen( temp );\r
-                       Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", game->magic, temp, i );\r
-                       \r
-                       /* this is slow, but only done once */\r
-                       for( j = 0; j < (len - len2); j++ )\r
-                       {\r
-                               /* check for the game's magic word */\r
-                               if( Q_strncasecmp( &temp[ j ], game->magic, len2 ) == 0 )\r
-                               {\r
-                                       /* now find the next slash and nuke everything after it */\r
-                                       while( temp[ ++j ] != '/' && temp[ j ] != '\0' );\r
-                                       temp[ j ] = '\0';\r
-                                       \r
-                                       /* add this as a base path */\r
-                                       AddBasePath( temp );\r
-                                       break;\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               /* add install path */\r
-               if( numBasePaths == 0 )\r
-                       AddBasePath( installPath );\r
-               \r
-               /* check again */\r
-               if( numBasePaths == 0 )\r
-                       Error( "Failed to find a valid base path." );\r
-       }\r
-       \r
-       /* this only affects unix */\r
-       AddHomeBasePath( game->homeBasePath );\r
-       \r
-       /* initialize vfs paths */\r
-       if( numBasePaths > MAX_BASE_PATHS )\r
-               numBasePaths = MAX_BASE_PATHS;\r
-       if( numGamePaths > MAX_GAME_PATHS )\r
-               numGamePaths = MAX_GAME_PATHS;\r
-       \r
-       /* walk the list of game paths */\r
-       for( j = 0; j < numGamePaths; j++ )\r
-       {\r
-               /* walk the list of base paths */\r
-               for( i = 0; i < numBasePaths; i++ )\r
-               {\r
-                       /* create a full path and initialize it */\r
-                       sprintf( temp, "%s/%s/", basePaths[ i ], gamePaths[ j ] );\r
-                       vfsInitDirectory( temp );\r
-               }\r
-       }\r
-       \r
-       /* done */\r
-       Sys_Printf( "\n" );\r
-}\r
-\r
-\r
-\r
-\r
+/* -------------------------------------------------------------------------------
+
+   Copyright (C) 1999-2007 id Software, Inc. and contributors.
+   For a list of contributors, see the accompanying CONTRIBUTORS file.
+
+   This file is part of GtkRadiant.
+
+   GtkRadiant is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   GtkRadiant is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GtkRadiant; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+   ----------------------------------------------------------------------------------
+
+   This code has been altered significantly from its original form, to support
+   several games based on the Quake III Arena engine, in the form of "Q3Map2."
+
+   ------------------------------------------------------------------------------- */
+
+
+
+/* marker */
+#define PATH_INIT_C
+
+
+
+/* dependencies */
+#include "q3map2.h"
+
+
+
+/* path support */
+#define MAX_BASE_PATHS  10
+#define MAX_GAME_PATHS  10
+#define MAX_PAK_PATHS  200
+
+char                    *homePath;
+char installPath[ MAX_OS_PATH ];
+
+int numBasePaths;
+char                    *basePaths[ MAX_BASE_PATHS ];
+int numGamePaths;
+char                    *gamePaths[ MAX_GAME_PATHS ];
+int numPakPaths;
+char                    *pakPaths[ MAX_PAK_PATHS ];
+char                    *homeBasePath = NULL;
+
+
+/*
+   some of this code is based off the original q3map port from loki
+   and finds various paths. moved here from bsp.c for clarity.
+ */
+
+/*
+   PathLokiGetHomeDir()
+   gets the user's home dir (for ~/.q3a)
+ */
+
+char *LokiGetHomeDir( void ){
+       #ifndef Q_UNIX
+       return NULL;
+       #else
+       static char     buf[ 4096 ];
+       struct passwd   pw, *pwp;
+       char            *home;
+       static char homeBuf[MAX_OS_PATH];
+
+
+       /* get the home environment variable */
+       home = getenv( "HOME" );
+
+       /* look up home dir in password database */
+       if(!home)
+       {
+               if ( getpwuid_r( getuid(), &pw, buf, sizeof( buf ), &pwp ) == 0 ) {
+                       return pw.pw_dir;
+               }
+       }
+
+       snprintf( homeBuf, sizeof( homeBuf ), "%s/.", home );
+
+       /* return it */
+       return homeBuf;
+       #endif
+}
+
+
+
+/*
+   PathLokiInitPaths()
+   initializes some paths on linux/os x
+ */
+
+void LokiInitPaths( char *argv0 ){
+       char        *home;
+
+       if ( !homePath ) {
+               /* get home dir */
+               home = LokiGetHomeDir();
+               if ( home == NULL ) {
+                       home = ".";
+               }
+
+               /* set home path */
+               homePath = home;
+       }
+       else{
+               home = homePath;
+       }
+
+       #ifndef Q_UNIX
+       /* this is kinda crap, but hey */
+       strcpy( installPath, "../" );
+       #else
+       char temp[ MAX_OS_PATH ];
+       char        *path;
+       char        *last;
+       qboolean found;
+
+
+       path = getenv( "PATH" );
+
+       /* do some path divining */
+       Q_strncpyz( temp, argv0, sizeof( temp ) );
+       if ( strrchr( temp, '/' ) ) {
+               argv0 = strrchr( argv0, '/' ) + 1;
+       }
+       else if ( path ) {
+
+               /*
+                  This code has a special behavior when q3map2 is a symbolic link.
+
+                  For each dir in ${PATH} (example: "/usr/bin", "/usr/local/bin" if ${PATH} == "/usr/bin:/usr/local/bin"),
+                  it looks for "${dir}/q3map2" (file exists and is executable),
+                  then it uses "dirname(realpath("${dir}/q3map2"))/../" as installPath.
+
+                  So, if "/usr/bin/q3map2" is a symbolic link to "/opt/radiant/tools/q3map2",
+                  it will find the installPath "/usr/share/radiant/",
+                  so q3map2 will look for "/opt/radiant/baseq3" to find paks.
+
+                  More precisely, it looks for "${dir}/${argv[0]}",
+                  so if "/usr/bin/q3map2" is a symbolic link to "/opt/radiant/tools/q3map2",
+                  and if "/opt/radiant/tools/q3ma2" is a symbolic link to "/opt/radiant/tools/q3map2.x86_64",
+                  it will use "dirname("/opt/radiant/tools/q3map2.x86_64")/../" as path,
+                  so it will use "/opt/radiant/" as installPath, which will be expanded later to "/opt/radiant/baseq3" to find paks.
+               */
+
+               found = qfalse;
+               last = path;
+
+               /* go through each : segment of path */
+               while ( last[ 0 ] != '\0' && found == qfalse )
+               {
+                       /* null out temp */
+                       temp[ 0 ] = '\0';
+
+                       /* find next chunk */
+                       last = strchr( path, ':' );
+                       if ( last == NULL ) {
+                               last = path + strlen( path );
+                       }
+
+                       /* found home dir candidate */
+                       if ( *path == '~' ) {
+                               Q_strncpyz( temp, home, sizeof( temp ) );
+                               path++;
+                       }
+
+
+                       /* concatenate */
+                       if ( last > ( path + 1 ) ) {
+                               // +1 hack: Q_strncat calls Q_strncpyz that expects a len including '\0'
+                               // so that extraneous char will be rewritten by '\0', so it's ok.
+                               // Also, in this case this extraneous char is always ':' or '\0', so it's ok.
+                               Q_strncat( temp, sizeof( temp ), path, ( last - path + 1) );
+                               Q_strcat( temp, sizeof( temp ), "/" );
+                       }
+                       Q_strcat( temp, sizeof( temp ), argv0 );
+
+                       /* verify the path */
+                       if ( access( temp, X_OK ) == 0 ) {
+                               found = qtrue;
+                       }
+                       path = last + 1;
+               }
+       }
+
+       /* flake */
+       if ( realpath( temp, installPath ) ) {
+               /*
+                  if "q3map2" is "/opt/radiant/tools/q3map2",
+                  installPath is "/opt/radiant"
+               */
+               *( strrchr( installPath, '/' ) ) = '\0';
+               *( strrchr( installPath, '/' ) ) = '\0';
+       }
+       #endif
+}
+
+
+
+/*
+   CleanPath() - ydnar
+   cleans a dos path \ -> /
+ */
+
+void CleanPath( char *path ){
+       while ( *path )
+       {
+               if ( *path == '\\' ) {
+                       *path = '/';
+               }
+               path++;
+       }
+}
+
+
+
+/*
+   GetGame() - ydnar
+   gets the game_t based on a -game argument
+   returns NULL if no match found
+ */
+
+game_t *GetGame( char *arg ){
+       int i;
+
+
+       /* dummy check */
+       if ( arg == NULL || arg[ 0 ] == '\0' ) {
+               return NULL;
+       }
+
+       /* joke */
+       if ( !Q_stricmp( arg, "quake1" ) ||
+                !Q_stricmp( arg, "quake2" ) ||
+                !Q_stricmp( arg, "unreal" ) ||
+                !Q_stricmp( arg, "ut2k3" ) ||
+                !Q_stricmp( arg, "dn3d" ) ||
+                !Q_stricmp( arg, "dnf" ) ||
+                !Q_stricmp( arg, "hl" ) ) {
+               Sys_Printf( "April fools, silly rabbit!\n" );
+               exit( 0 );
+       }
+
+       /* test it */
+       i = 0;
+       while ( games[ i ].arg != NULL )
+       {
+               if ( Q_stricmp( arg, games[ i ].arg ) == 0 ) {
+                       return &games[ i ];
+               }
+               i++;
+       }
+
+       /* no matching game */
+       return NULL;
+}
+
+
+
+/*
+   AddBasePath() - ydnar
+   adds a base path to the list
+ */
+
+void AddBasePath( char *path ){
+       /* dummy check */
+       if ( path == NULL || path[ 0 ] == '\0' || numBasePaths >= MAX_BASE_PATHS ) {
+               return;
+       }
+
+       /* add it to the list */
+       basePaths[ numBasePaths ] = safe_malloc( strlen( path ) + 1 );
+       strcpy( basePaths[ numBasePaths ], path );
+       CleanPath( basePaths[ numBasePaths ] );
+       numBasePaths++;
+}
+
+
+
+/*
+   AddHomeBasePath() - ydnar
+   adds a base path to the beginning of the list, prefixed by ~/
+ */
+
+void AddHomeBasePath( char *path ){
+       int i;
+       char temp[ MAX_OS_PATH ];
+       int homePathLen;
+
+       if ( !homePath ) {
+               return;
+       }
+
+       /* dummy check */
+       if ( path == NULL || path[ 0 ] == '\0' ) {
+               return;
+       }
+
+       /* strip leading dot, if homePath does not end in /. */
+       homePathLen = strlen( homePath );
+       if ( !strcmp( path, "." ) ) {
+               /* -fs_homebase . means that -fs_home is to be used as is */
+               strcpy( temp, homePath );
+       }
+       else if ( homePathLen >= 2 && !strcmp( homePath + homePathLen - 2, "/." ) ) {
+               /* remove trailing /. of homePath */
+               homePathLen -= 2;
+
+               /* concatenate home dir and path */
+               sprintf( temp, "%.*s/%s", homePathLen, homePath, path );
+       }
+       else
+       {
+               /* remove leading . of path */
+               if ( path[0] == '.' ) {
+                       ++path;
+               }
+
+               /* concatenate home dir and path */
+               sprintf( temp, "%s/%s", homePath, path );
+       }
+
+       /* make a hole */
+       for ( i = ( MAX_BASE_PATHS - 2 ); i >= 0; i-- )
+               basePaths[ i + 1 ] = basePaths[ i ];
+
+       /* add it to the list */
+       basePaths[ 0 ] = safe_malloc( strlen( temp ) + 1 );
+       strcpy( basePaths[ 0 ], temp );
+       CleanPath( basePaths[ 0 ] );
+       numBasePaths++;
+}
+
+
+
+/*
+   AddGamePath() - ydnar
+   adds a game path to the list
+ */
+
+void AddGamePath( char *path ){
+       int i;
+
+       /* dummy check */
+       if ( path == NULL || path[ 0 ] == '\0' || numGamePaths >= MAX_GAME_PATHS ) {
+               return;
+       }
+
+       /* add it to the list */
+       gamePaths[ numGamePaths ] = safe_malloc( strlen( path ) + 1 );
+       strcpy( gamePaths[ numGamePaths ], path );
+       CleanPath( gamePaths[ numGamePaths ] );
+       numGamePaths++;
+
+       /* don't add it if it's already there */
+       for ( i = 0; i < numGamePaths - 1; i++ )
+       {
+               if ( strcmp( gamePaths[i], gamePaths[numGamePaths - 1] ) == 0 ) {
+                       free( gamePaths[numGamePaths - 1] );
+                       gamePaths[numGamePaths - 1] = NULL;
+                       numGamePaths--;
+                       break;
+               }
+       }
+
+}
+
+
+/*
+   AddPakPath()
+   adds a pak path to the list
+ */
+
+void AddPakPath( char *path ){
+       /* dummy check */
+       if ( path == NULL || path[ 0 ] == '\0' || numPakPaths >= MAX_PAK_PATHS ) {
+               return;
+       }
+
+       /* add it to the list */
+       pakPaths[ numPakPaths ] = safe_malloc( strlen( path ) + 1 );
+       strcpy( pakPaths[ numPakPaths ], path );
+       CleanPath( pakPaths[ numPakPaths ] );
+       numPakPaths++;
+}
+
+
+
+/*
+   InitPaths() - ydnar
+   cleaned up some of the path initialization code from bsp.c
+   will remove any arguments it uses
+ */
+
+void InitPaths( int *argc, char **argv ){
+       int i, j, k, len, len2;
+       char temp[ MAX_OS_PATH ];
+
+       int noBasePath = 0;
+       int noHomePath = 0;
+
+       /* note it */
+       Sys_FPrintf( SYS_VRB, "--- InitPaths ---\n" );
+
+       /* get the install path for backup */
+       LokiInitPaths( argv[ 0 ] );
+
+       /* set game to default (q3a) */
+       game = &games[ 0 ];
+       numBasePaths = 0;
+       numGamePaths = 0;
+
+       /* parse through the arguments and extract those relevant to paths */
+       for ( i = 0; i < *argc; i++ )
+       {
+               /* check for null */
+               if ( argv[ i ] == NULL ) {
+                       continue;
+               }
+
+               /* -game */
+               if ( strcmp( argv[ i ], "-game" ) == 0 ) {
+                       if ( ++i >= *argc ) {
+                               Error( "Out of arguments: No game specified after %s", argv[ i - 1 ] );
+                       }
+                       argv[ i - 1 ] = NULL;
+                       game = GetGame( argv[ i ] );
+                       if ( game == NULL ) {
+                               game = &games[ 0 ];
+                       }
+                       argv[ i ] = NULL;
+               }
+
+               /* -fs_forbiddenpath */
+               else if ( strcmp( argv[ i ], "-fs_forbiddenpath" ) == 0 ) {
+                       if ( ++i >= *argc ) {
+                               Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
+                       }
+                       argv[ i - 1 ] = NULL;
+                       if ( g_numForbiddenDirs < VFS_MAXDIRS ) {
+                               strncpy( g_strForbiddenDirs[g_numForbiddenDirs], argv[i], PATH_MAX );
+                               g_strForbiddenDirs[g_numForbiddenDirs][PATH_MAX] = 0;
+                               ++g_numForbiddenDirs;
+                       }
+                       argv[ i ] = NULL;
+               }
+
+               /* -fs_nobasepath */
+               else if ( strcmp( argv[ i ], "-fs_nobasepath" ) == 0 ) {
+                       noBasePath = 1;
+                       argv[ i ] = NULL;
+               }               
+
+               /* -fs_basepath */
+               else if ( strcmp( argv[ i ], "-fs_basepath" ) == 0 ) {
+                       if ( ++i >= *argc ) {
+                               Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
+                       }
+                       argv[ i - 1 ] = NULL;
+                       AddBasePath( argv[ i ] );
+                       argv[ i ] = NULL;
+               }
+
+               /* -fs_game */
+               else if ( strcmp( argv[ i ], "-fs_game" ) == 0 ) {
+                       if ( ++i >= *argc ) {
+                               Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
+                       }
+                       argv[ i - 1 ] = NULL;
+                       AddGamePath( argv[ i ] );
+                       argv[ i ] = NULL;
+               }
+
+               /* -fs_home */
+               else if ( strcmp( argv[ i ], "-fs_home" ) == 0 ) {
+                       if ( ++i >= *argc ) {
+                               Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
+                       }
+                       argv[ i - 1 ] = NULL;
+                       homePath = argv[i];
+                       argv[ i ] = NULL;
+               }
+
+               /* -fs_nohomepath */
+               else if ( strcmp( argv[ i ], "-fs_nohomepath" ) == 0 ) {
+                       noHomePath = 1;
+                       argv[ i ] = NULL;
+               }               
+
+               /* -fs_homebase */
+               else if ( strcmp( argv[ i ], "-fs_homebase" ) == 0 ) {
+                       if ( ++i >= *argc ) {
+                               Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
+                       }
+                       argv[ i - 1 ] = NULL;
+                       homeBasePath = argv[i];
+                       argv[ i ] = NULL;
+               }
+
+               /* -fs_homepath - sets both of them */
+               else if ( strcmp( argv[ i ], "-fs_homepath" ) == 0 ) {
+                       if ( ++i >= *argc ) {
+                               Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
+                       }
+                       argv[ i - 1 ] = NULL;
+                       homePath = argv[i];
+                       homeBasePath = ".";
+                       argv[ i ] = NULL;
+               }
+
+               /* -fs_pakpath */
+               else if ( strcmp( argv[ i ], "-fs_pakpath" ) == 0 ) {
+                       if ( ++i >= *argc ) {
+                               Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
+                       }
+                       argv[ i - 1 ] = NULL;
+                       AddPakPath( argv[ i ] );
+                       argv[ i ] = NULL;
+               }
+
+       }
+
+       /* remove processed arguments */
+       for ( i = 0, j = 0, k = 0; i < *argc && j < *argc; i++, j++ )
+       {
+               for ( ; j < *argc && argv[ j ] == NULL; j++ ) ;
+               argv[ i ] = argv[ j ];
+               if ( argv[ i ] != NULL ) {
+                       k++;
+               }
+       }
+       *argc = k;
+
+       /* add standard game path */
+       AddGamePath( game->gamePath );
+
+       /* if there is no base path set, figure it out */
+       if ( numBasePaths == 0 && noBasePath == 0 ) {
+               /* this is another crappy replacement for SetQdirFromPath() */
+               len2 = strlen( game->magic );
+               for ( i = 0; i < *argc && numBasePaths == 0; i++ )
+               {
+                       /* extract the arg */
+                       strcpy( temp, argv[ i ] );
+                       CleanPath( temp );
+                       len = strlen( temp );
+                       Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", game->magic, temp, i );
+
+                       /* this is slow, but only done once */
+                       for ( j = 0; j < ( len - len2 ); j++ )
+                       {
+                               /* check for the game's magic word */
+                               if ( Q_strncasecmp( &temp[ j ], game->magic, len2 ) == 0 ) {
+                                       /* now find the next slash and nuke everything after it */
+                                       while ( temp[ ++j ] != '/' && temp[ j ] != '\0' ) ;
+                                       temp[ j ] = '\0';
+
+                                       /* add this as a base path */
+                                       AddBasePath( temp );
+                                       break;
+                               }
+                       }
+               }
+
+               /* add install path */
+               if ( numBasePaths == 0 ) {
+                       AddBasePath( installPath );
+               }
+
+               /* check again */
+               if ( numBasePaths == 0 ) {
+                       Error( "Failed to find a valid base path." );
+               }
+       }
+
+       if ( noBasePath == 1 ) {
+               numBasePaths = 0;
+       }
+
+       if ( noHomePath == 0 ) {
+               /* this only affects unix */
+               if ( homeBasePath ) {
+                       AddHomeBasePath( homeBasePath );
+               }
+               else{
+                       AddHomeBasePath( game->homeBasePath );
+               }
+       }
+
+       /* initialize vfs paths */
+       if ( numBasePaths > MAX_BASE_PATHS ) {
+               numBasePaths = MAX_BASE_PATHS;
+       }
+       if ( numGamePaths > MAX_GAME_PATHS ) {
+               numGamePaths = MAX_GAME_PATHS;
+       }
+
+       /* walk the list of game paths */
+       for ( j = 0; j < numGamePaths; j++ )
+       {
+               /* walk the list of base paths */
+               for ( i = 0; i < numBasePaths; i++ )
+               {
+                       /* create a full path and initialize it */
+                       sprintf( temp, "%s/%s/", basePaths[ i ], gamePaths[ j ] );
+                       vfsInitDirectory( temp );
+               }
+       }
+
+       /* initialize vfs paths */
+       if ( numPakPaths > MAX_PAK_PATHS ) {
+               numPakPaths = MAX_PAK_PATHS;
+       }
+
+       /* walk the list of pak paths */
+       for ( i = 0; i < numPakPaths; i++ )
+       {
+               /* initialize this pak path */
+               vfsInitDirectory( pakPaths[ i ] );
+       }
+
+       /* done */
+       Sys_Printf( "\n" );
+}