Skip to content

Commit

Permalink
Add --appendconfig option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Sep 10, 2012
1 parent ddcc311 commit a8ab9c5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions conf/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@ static bool parse_line(config_file_t *conf, struct entry_list *list, char *line)
return true;
}

bool config_append_file(config_file_t *conf, const char *path)
{
config_file_t *new_conf = config_file_new(path);
if (!new_conf)
return false;

if (new_conf->tail)
{
new_conf->tail->next = conf->entries;
conf->entries = new_conf->entries; // Pilfer.
new_conf->entries = NULL;
}

config_file_free(new_conf);
return true;
}

static config_file_t *config_file_new_internal(const char *path, unsigned depth)
{
struct config_file *conf = (struct config_file*)calloc(1, sizeof(*conf));
Expand Down
4 changes: 4 additions & 0 deletions conf/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ config_file_t *config_file_new(const char *path);
// Frees config file.
void config_file_free(config_file_t *conf);

// Loads a new config, and appends its data to conf.
// The key-value pairs of the new config file takes priority over the old.
bool config_append_file(config_file_t *conf, const char *path);

// All extract functions return true when value is valid and exists.
// Returns false otherwise.

Expand Down
6 changes: 6 additions & 0 deletions docs/retroarch.1
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ If PATH is a directory, RetroArch will treat this as the config file directory,
When loading a rom from stdin, the path must be a full path, however.
If a config cannot be found when using directory path, the default config path will be used instead.

.TP
\fB--appendconfig PATH\fR
Appends a different set of config files to the config file loaded in -c (or default).
Multiple config files are delimited by ','.
Every config file will be appended in order where the key-value pairs of the next config file takes priority over the old ones.

.IP
Unix-like systems will look in $XDG_CONFIG_HOME/retroarch/retroarch.cfg first. Then it will try $HOME/.retroarch.cfg. Last, it will try /etc/retroarch.cfg. If no configuration is found, default settings will be assumed. A configuration file does not need to define every possible option, only those that should be overridden.

Expand Down
1 change: 1 addition & 0 deletions general.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ struct global

#ifdef HAVE_CONFIGFILE
char config_path[PATH_MAX];
char append_config_path[PATH_MAX];
#endif

char basename[PATH_MAX];
Expand Down
7 changes: 7 additions & 0 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ static void print_help(void)
puts("\t-S/--savestate: Path to use for save states. If not selected, *.state will be assumed.");
#ifdef HAVE_CONFIGFILE
puts("\t-c/--config: Path for config file." RARCH_DEFAULT_CONF_PATH_STR);
puts("\t--appendconfig: Extra config files are loaded in, and take priority over config selected in -c (or default).");
puts("\t\tMultiple configs are delimited by ','.");
#endif
#ifdef HAVE_DYNAMIC
puts("\t-L/--libretro: Path to libretro implementation. Overrides any config setting.");
Expand Down Expand Up @@ -768,6 +770,7 @@ static void parse_input(int argc, char *argv[])
{ "gameboy", 1, NULL, 'g' },
#ifdef HAVE_CONFIGFILE
{ "config", 1, NULL, 'c' },
{ "appendconfig", 1, &val, 'C' },
#endif
{ "mouse", 1, NULL, 'm' },
{ "nodevice", 1, NULL, 'N' },
Expand Down Expand Up @@ -1048,6 +1051,10 @@ static void parse_input(int argc, char *argv[])
break;
#endif

case 'C':
strlcpy(g_extern.append_config_path, optarg, sizeof(g_extern.append_config_path));
break;

case 'B':
strlcpy(g_extern.bps_name, optarg, sizeof(g_extern.bps_name));
g_extern.bps_pref = true;
Expand Down
13 changes: 13 additions & 0 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ bool config_load_file(const char *path)
if (conf == NULL)
return true;

char *save;
char tmp_append_path[PATH_MAX]; // Don't destroy append_config_path.
strlcpy(tmp_append_path, g_extern.append_config_path, sizeof(tmp_append_path));
const char *extra_path = strtok_r(tmp_append_path, ",", &save);
while (extra_path)
{
RARCH_LOG("Appending config \"%s\"\n", extra_path);
bool ret = config_append_file(conf, extra_path);
if (!ret)
RARCH_ERR("Failed to append config \"%s\"\n", extra_path);
extra_path = strtok_r(NULL, ";", &save);
}

if (g_extern.verbose)
{
fprintf(stderr, "=== Config ===\n");
Expand Down

0 comments on commit a8ab9c5

Please sign in to comment.