From a8ab9c54bc1265a6abe42f2ea5b48363d3ead1f8 Mon Sep 17 00:00:00 2001 From: Themaister Date: Tue, 11 Sep 2012 00:10:44 +0200 Subject: [PATCH] Add --appendconfig option. --- conf/config_file.c | 17 +++++++++++++++++ conf/config_file.h | 4 ++++ docs/retroarch.1 | 6 ++++++ general.h | 1 + retroarch.c | 7 +++++++ settings.c | 13 +++++++++++++ 6 files changed, 48 insertions(+) diff --git a/conf/config_file.c b/conf/config_file.c index b004849558..b8172ba688 100644 --- a/conf/config_file.c +++ b/conf/config_file.c @@ -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)); diff --git a/conf/config_file.h b/conf/config_file.h index e04383fdb7..a7fff9180a 100644 --- a/conf/config_file.h +++ b/conf/config_file.h @@ -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. diff --git a/docs/retroarch.1 b/docs/retroarch.1 index d439d65c6e..42e0c9bdee 100644 --- a/docs/retroarch.1 +++ b/docs/retroarch.1 @@ -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. diff --git a/general.h b/general.h index 13874e8861..67ff83fac6 100644 --- a/general.h +++ b/general.h @@ -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]; diff --git a/retroarch.c b/retroarch.c index 70f45b3ad1..21ff9201e3 100644 --- a/retroarch.c +++ b/retroarch.c @@ -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."); @@ -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' }, @@ -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; diff --git a/settings.c b/settings.c index 563afe884d..e8e744d421 100644 --- a/settings.c +++ b/settings.c @@ -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");