X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=tools%2Fquake3%2Fq3map2%2Fpath_init.c;h=07ebc31b1e154dc2ade01a871560ad49a3b1635a;hp=901f07fc3f64db841221fd26e82558564fab6d29;hb=b7e36c120eb1546a6c6f97f30e42ab7f9a559c61;hpb=686a211fc38285905245e537acf9d96e66b9675c diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index 901f07fc..07ebc31b 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -49,7 +49,7 @@ int numBasePaths; char *basePaths[ MAX_BASE_PATHS ]; int numGamePaths; char *gamePaths[ MAX_GAME_PATHS ]; - +char *homeBasePath = NULL; /* @@ -69,20 +69,24 @@ char *LokiGetHomeDir( void ){ static char buf[ 4096 ]; struct passwd pw, *pwp; char *home; + static char homeBuf[MAX_OS_PATH]; /* get the home environment variable */ home = getenv( "HOME" ); - if ( home ) { - return Q_strncpyz( buf, home, sizeof( buf ) ); - } /* look up home dir in password database */ - if ( getpwuid_r( getuid(), &pw, buf, sizeof( buf ), &pwp ) == 0 ) { - return pw.pw_dir; + if(!home) + { + if ( getpwuid_r( getuid(), &pw, buf, sizeof( buf ), &pwp ) == 0 ) { + return pw.pw_dir; + } } - return NULL; + snprintf( homeBuf, sizeof( homeBuf ), "%s/.", home ); + + /* return it */ + return homeBuf; #endif } @@ -94,23 +98,33 @@ char *LokiGetHomeDir( void ){ */ 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 *home; + char last0[ 2 ]; char *path; char *last; qboolean found; - /* get home dir */ - home = LokiGetHomeDir(); - if ( home == NULL ) { - home = "."; - } - path = getenv( "PATH" ); /* do some path divining */ @@ -162,9 +176,6 @@ void LokiInitPaths( char *argv0 ){ *( strrchr( installPath, '/' ) ) = '\0'; *( strrchr( installPath, '/' ) + 1 ) = '\0'; } - - /* set home path */ - homePath = home; #endif } @@ -256,29 +267,52 @@ void AddBasePath( char *path ){ */ void AddHomeBasePath( char *path ){ - #ifdef Q_UNIX 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 = 0; i < ( MAX_BASE_PATHS - 1 ); i++ ) + 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 } @@ -361,6 +395,20 @@ void InitPaths( int *argc, char **argv ){ 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_basepath */ else if ( strcmp( argv[ i ], "-fs_basepath" ) == 0 ) { if ( ++i >= *argc ) { @@ -380,6 +428,37 @@ void InitPaths( int *argc, char **argv ){ 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_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; + } } /* remove processed arguments */ @@ -436,7 +515,12 @@ void InitPaths( int *argc, char **argv ){ } /* this only affects unix */ - AddHomeBasePath( game->homeBasePath ); + if ( homeBasePath ) { + AddHomeBasePath( homeBasePath ); + } + else{ + AddHomeBasePath( game->homeBasePath ); + } /* initialize vfs paths */ if ( numBasePaths > MAX_BASE_PATHS ) {