move check for configured program base directory to appropriate function
authorHolger Schemel <info@artsoft.org>
Tue, 7 Nov 2017 22:14:56 +0000 (23:14 +0100)
committerHolger Schemel <info@artsoft.org>
Fri, 23 Mar 2018 22:21:16 +0000 (23:21 +0100)
src/libgame/misc.c

index 2116630707fc7bcb423a8cf51a4844a52cadc638..7ac8d566362aef4a052b16909e9d1a3b3f92e963 100644 (file)
@@ -696,8 +696,16 @@ char *getBasePath(char *filename)
   return basepath;
 }
 
-static char *getProgramMainDataPath(char *command_filename)
+static char *getProgramMainDataPath(char *command_filename, char *base_path)
 {
+  /* check if the program's main data base directory is configured */
+  if (!strEqual(base_path, "."))
+    return base_path;
+
+  /* if the program is configured to start from current directory (default),
+     determine program package directory from program binary (some versions
+     of KDE/Konqueror and Mac OS X (especially "Mavericks") apparently do not
+     set the current working directory to the program package directory) */
   char *main_data_path = getBasePath(command_filename);
 
 #if defined(PLATFORM_MACOSX)
@@ -940,8 +948,8 @@ void GetOptions(int argc, char *argv[],
                void (*print_usage_function)(void),
                void (*print_version_function)(void))
 {
-  char *ro_base_path = RO_BASE_PATH;
-  char *rw_base_path = RW_BASE_PATH;
+  char *ro_base_path = getProgramMainDataPath(argv[0], RO_BASE_PATH);
+  char *rw_base_path = getProgramMainDataPath(argv[0], RW_BASE_PATH);
   char **argvplus = checked_calloc((argc + 1) * sizeof(char **));
   char **options_left = &argvplus[1];
 
@@ -949,16 +957,6 @@ void GetOptions(int argc, char *argv[],
   while (argc--)
     argvplus[argc] = argv[argc];
 
-  /* if the program is configured to start from current directory (default),
-     determine program package directory from program binary (some versions
-     of KDE/Konqueror and Mac OS X (especially "Mavericks") apparently do not
-     set the current working directory to the program package directory) */
-
-  if (strEqual(ro_base_path, "."))
-    ro_base_path = getProgramMainDataPath(argv[0]);
-  if (strEqual(rw_base_path, "."))
-    rw_base_path = getProgramMainDataPath(argv[0]);
-
   /* initialize global program options */
   options.server_host = NULL;
   options.server_port = 0;