]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/path_init.c
experimental q3map2 command line option: -sRGB (store lightmaps in sRGB)
[xonotic/netradiant.git] / tools / quake3 / q3map2 / path_init.c
index e6b4d959b7d06f16dff3f7b17204edb0d7ad9e89..4994c5f5712af05ac4fa3c7e967e97d86ecffaed 100644 (file)
@@ -62,7 +62,7 @@ PathLokiGetHomeDir()
 gets the user's home dir (for ~/.q3a)
 */
 
-char *LokiGetHomeDir( void )
+char *LokiGetHomeDir(void)
 {
        #ifndef Q_UNIX
                return NULL;
@@ -70,6 +70,7 @@ char *LokiGetHomeDir( void )
                char                    *home;
                uid_t                   id;
                struct passwd   *pwd;
+               static char homeBuf[MAX_OS_PATH];
                
                
                /* get the home environment variable */
@@ -89,9 +90,11 @@ char *LokiGetHomeDir( void )
                        }
                        endpwent();
                }
+
+               snprintf(homeBuf, sizeof(homeBuf), "%s/.", home);
                
                /* return it */
-               return home;
+               return homeBuf;
        #endif
 }
 
@@ -104,23 +107,32 @@ 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            last0[ 2 ];
-               char            *home;
                char            *path;
                char            *last;
                qboolean        found;
                
                
-               /* get home dir */
-               home = LokiGetHomeDir();
-               if( home == NULL )
-                       home = ".";
-               
                /* do some path divining */
                strcpy( temp, argv0 );
                if( strrchr( argv0, '/' ) )
@@ -177,9 +189,6 @@ void LokiInitPaths( char *argv0 )
                        *(strrchr( installPath, '/' )) = '\0';
                        *(strrchr( installPath, '/' ) + 1) = '\0';
                }
-               
-               /* set home path */
-               homePath = home;
        #endif
 }
 
@@ -272,28 +281,51 @@ adds a base path to the beginning of the list, prefixed by ~/
 
 void AddHomeBasePath( char *path )
 {
-       #ifdef Q_UNIX
-               int             i;
-               char    temp[ MAX_OS_PATH ];
-               
-               
-               /* dummy check */
-               if( path == NULL || path[ 0 ] == '\0' )
-                       return;
+       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;
 
-               /* make a hole */
-               for( i = (MAX_BASE_PATHS - 2); i >= 0; i-- )
-                       basePaths[ i + 1 ] = basePaths[ i ];
-               
                /* concatenate home dir and path */
                sprintf( temp, "%s/%s", homePath, path );
-               
-               /* add it to the list */
-               basePaths[ 0 ] = safe_malloc( strlen( temp ) + 1 );
-               strcpy( basePaths[ 0 ], temp );
-               CleanPath( basePaths[ 0 ] );
-               numBasePaths++;
-       #endif
+       }
+       
+       /* 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++;
 }
 
 
@@ -305,6 +337,8 @@ 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;
@@ -314,6 +348,19 @@ void AddGamePath( char *path )
        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;
+               }
+       }
+       
 }
 
 
@@ -396,7 +443,17 @@ void InitPaths( int *argc, char **argv )
                        argv[ i ] = NULL;
                }
                
-               /* -fs_nohomebase */
+               /* -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_homebase */
                else if( strcmp( argv[ i ], "-fs_homebase" ) == 0 )
                {
                        if( ++i >= *argc )
@@ -405,6 +462,17 @@ void InitPaths( int *argc, char **argv )
                        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;
+               }
        }
        
        /* remove processed arguments */