]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/path_init.c
Merge branch 'nomagicpath' into 'master'
[xonotic/netradiant.git] / tools / quake3 / q3map2 / path_init.c
index 16758c6db40fecf7de6df655aadc03b8f8f47e4b..80cdbcae5d4e1fb50d571b72532c6c4919000df7 100644 (file)
@@ -101,7 +101,7 @@ char *LokiGetHomeDir( void ){
  */
 
 void LokiInitPaths( char *argv0 ){
-       char        *home;
+       char *home;
 
        if ( !homePath ) {
                /* get home dir */
@@ -121,10 +121,10 @@ void LokiInitPaths( char *argv0 ){
        /* this is kinda crap, but hey */
        strcpy( installPath, "../" );
        #else
+
        char temp[ MAX_OS_PATH ];
-       char last0[ 2 ];
-       char        *path;
-       char        *last;
+       char *path;
+       char *last;
        qboolean found;
 
 
@@ -136,6 +136,25 @@ void LokiInitPaths( char *argv0 ){
                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;
 
@@ -159,15 +178,17 @@ void LokiInitPaths( char *argv0 ){
 
                        /* concatenate */
                        if ( last > ( path + 1 ) ) {
-                               Q_strncat( temp, sizeof( temp ), path, ( last - path ) );
+                               // +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 ), "./" );
                        Q_strcat( temp, sizeof( temp ), argv0 );
 
                        /* verify the path */
                        if ( access( temp, X_OK ) == 0 ) {
-                               found++;
+                               found = qtrue;
                        }
                        path = last + 1;
                }
@@ -175,9 +196,12 @@ void LokiInitPaths( char *argv0 ){
 
        /* flake */
        if ( realpath( temp, installPath ) ) {
-               /* q3map is in "tools/" */
+               /*
+                  if "q3map2" is "/opt/radiant/tools/q3map2",
+                  installPath is "/opt/radiant"
+               */
+               *( strrchr( installPath, '/' ) ) = '\0';
                *( strrchr( installPath, '/' ) ) = '\0';
-               *( strrchr( installPath, '/' ) + 1 ) = '\0';
        }
        #endif
 }
@@ -383,6 +407,9 @@ void InitPaths( int *argc, char **argv ){
        int i, j, k, len, len2;
        char temp[ MAX_OS_PATH ];
 
+       int noBasePath = 0;
+       int noHomePath = 0;
+       int noMagicPath = 0;
 
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- InitPaths ---\n" );
@@ -430,6 +457,20 @@ void InitPaths( int *argc, char **argv ){
                        argv[ i ] = NULL;
                }
 
+               /* -fs_nobasepath */
+               else if ( strcmp( argv[ i ], "-fs_nobasepath" ) == 0 ) {
+                       noBasePath = 1;
+                       // we don't want any basepath, neither guessed ones
+                       noMagicPath = 1;
+                       argv[ i ] = NULL;
+               }               
+
+               /* -fs_nomagicpath */
+               else if ( strcmp( argv[ i ], "-fs_nomagicpath") == 0) {
+                       noMagicPath = 1;
+                       argv[ i ] = NULL;
+               }
+
                /* -fs_basepath */
                else if ( strcmp( argv[ i ], "-fs_basepath" ) == 0 ) {
                        if ( ++i >= *argc ) {
@@ -460,6 +501,12 @@ void InitPaths( int *argc, char **argv ){
                        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 ) {
@@ -490,7 +537,6 @@ void InitPaths( int *argc, char **argv ){
                        AddPakPath( argv[ i ] );
                        argv[ i ] = NULL;
                }
-
        }
 
        /* remove processed arguments */
@@ -507,8 +553,8 @@ void InitPaths( int *argc, char **argv ){
        /* add standard game path */
        AddGamePath( game->gamePath );
 
-       /* if there is no base path set, figure it out */
-       if ( numBasePaths == 0 ) {
+       /* if there is no base path set, figure it out unless fs_nomagicpath is set */
+       if ( numBasePaths == 0 && noBasePath == 0 && noMagicPath == 0 ) {
                /* this is another crappy replacement for SetQdirFromPath() */
                len2 = strlen( game->magic );
                for ( i = 0; i < *argc && numBasePaths == 0; i++ )
@@ -546,12 +592,18 @@ void InitPaths( int *argc, char **argv ){
                }
        }
 
-       /* this only affects unix */
-       if ( homeBasePath ) {
-               AddHomeBasePath( homeBasePath );
+       if ( noBasePath == 1 ) {
+               numBasePaths = 0;
        }
-       else{
-               AddHomeBasePath( game->homeBasePath );
+
+       if ( noHomePath == 0 ) {
+               /* this only affects unix */
+               if ( homeBasePath ) {
+                       AddHomeBasePath( homeBasePath );
+               }
+               else{
+                       AddHomeBasePath( game->homeBasePath );
+               }
        }
 
        /* initialize vfs paths */