return getStringCopy(getBaseNamePtr(filename));
}
+char *getBaseNameNoSuffix(char *filename)
+{
+ char *basename = getStringCopy(getBaseNamePtr(filename));
+
+ // remove trailing suffix (separated by dot or hyphen)
+ if (basename[0] != '.' && basename[0] != '-')
+ {
+ if (strchr(basename, '.') != NULL)
+ *strchr(basename, '.') = '\0';
+
+ if (strchr(basename, '-') != NULL)
+ *strchr(basename, '-') = '\0';
+ }
+
+ return basename;
+}
+
char *getBasePath(char *filename)
{
char *basepath = getStringCopy(filename);
char *getBasePath(char *);
char *getBaseName(char *);
char *getBaseNamePtr(char *);
+char *getBaseNameNoSuffix(char *);
char *getStringCat2WithSeparator(char *, char *, char *);
char *getStringCat3WithSeparator(char *, char *, char *, char *);
char *getProgramConfigFilename(char *command_filename_ptr)
{
- char *command_filename = getStringCopy(command_filename_ptr);
+ char *command_filename_1 = getStringCopy(command_filename_ptr);
// strip trailing executable suffix from command filename
- if (strSuffix(command_filename, ".exe"))
- command_filename[strlen(command_filename) - 4] = '\0';
+ if (strSuffix(command_filename_1, ".exe"))
+ command_filename_1[strlen(command_filename_1) - 4] = '\0';
- return getStringCat2(command_filename, ".conf");
+ char *command_basepath = getBasePath(command_filename_ptr);
+ char *command_basename = getBaseNameNoSuffix(command_filename_ptr);
+ char *command_filename_2 = getPath2(command_basepath, command_basename);
+
+ char *config_filename_1 = getStringCat2(command_filename_1, ".conf");
+ char *config_filename_2 = getStringCat2(command_filename_2, ".conf");
+
+ // 1st try: look for config file that exactly matches the binary filename
+ if (fileExists(config_filename_1))
+ return config_filename_1;
+
+ // 2nd try: return config filename that matches binary filename without suffix
+ return config_filename_2;
}
char *getTapeFilename(int nr)
static void InitProgramConfig(char *command_filename)
{
- char *command_basename = getBaseName(command_filename);
+ char *userdata_basename = getBaseNameNoSuffix(command_filename);
char *config_filename = getProgramConfigFilename(command_filename);
char *program_title = PROGRAM_TITLE_STRING;
char *program_icon_file = PROGRAM_ICON_FILENAME;
// read default program config, if existing
if (fileExists(config_filename))
+ {
+ // if program config file exists, derive Unix user data directory from it
+ userdata_basename = getBaseName(config_filename);
+
+ if (strSuffix(userdata_basename, ".conf"))
+ userdata_basename[strlen(userdata_basename) - 4] = '\0';
+
LoadSetupFromFilename(config_filename);
+ }
+
+ // set user data directory for Linux/Unix (but not Mac OS X)
+ userdata_subdir_unix = getStringCat2(".", userdata_basename);
// set program title from potentially redefined program title
if (setup.internal.program_title != NULL &&
strlen(setup.internal.program_icon_file) > 0)
program_icon_file = getStringCopy(setup.internal.program_icon_file);
- // strip trailing executable suffix from command basename
- if (strSuffix(command_basename, ".exe"))
- command_basename[strlen(command_basename) - 4] = '\0';
-
- userdata_subdir_unix = getStringCat2(".", command_basename);
-
#if defined(PLATFORM_WIN32) || defined(PLATFORM_MACOSX)
userdata_subdir = program_title;
#elif defined(PLATFORM_UNIX)