From 54b29e831c6bbebc46f26e124a93871f51c3dea8 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Sun, 8 Oct 2006 19:26:04 +0000 Subject: [PATCH] Change configfile loading support. Introduce some sort of global configfile parsing and add some additional settings from local configuration files. Allow multiple configuration files to be specified at the commandline like patch 1513790. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2705 --- README | 9 ++++++--- docs/dosbox.1 | 12 ++++++++---- src/gui/sdlmain.cpp | 34 ++++++++++++++++------------------ src/misc/setup.cpp | 8 ++++++-- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/README b/README index 6ce98d72..fbf0ff68 100644 --- a/README +++ b/README @@ -226,6 +226,7 @@ dosbox -version -conf configfile Start DOSBox with the options specified in "configfile". + Multiple -conf options may be present. See Chapter 9 for more details. -lang languagefile @@ -770,9 +771,11 @@ Some sections have options you can set. The generated configfile contains the current settings. You can alter them and start DOSBox with the -conf switch to load the file and use these settings. -If no configfile is specified with the -conf switch, DOSBox will look in the -current directory for dosbox.conf. Then it will look for ~/.dosboxrc (Linux), -~\dosbox.conf (Win32) or "~/Library/Preferences/DOSBox Preferences" (MACOSX). +DOSBox will first parse the settings in ~/.dosboxrc (Linux), +~\dosbox.conf (Win32) or "~/Library/Preferences/DOSBox Preferences" +(MACOSX). Afterwards DOSBox will parse all configfiles specified with the +-conf switch. If no configfile is specified with the -conf switch, DOSBox will +look in the current directory for dosbox.conf. diff --git a/docs/dosbox.1 b/docs/dosbox.1 index cfe18ada..8751a594 100644 --- a/docs/dosbox.1 +++ b/docs/dosbox.1 @@ -49,7 +49,8 @@ an Internal Program, a DOS command or an executable on a mounted drive. .BI \-conf " configfile .RB "Start " dosbox " with the options specified in " .IR configfile ". This file has a section in which you can put commands you " -wish to execute on startup. +wish to execute on startup. Multiple +.IR configfiles " can be present at the commandline." .TP .BI \-lang " langfile .RB "Start " dosbox " with the language specified in " @@ -211,9 +212,12 @@ Boot will start floppy images or hard disk images independent of the .RB "Read the " README " of " dosbox " for the full and correct syntax." .RE .SH FILES -Configuration and language files use a format similar to Windows .ini files. If a file named -.BR dosbox.conf " is found in the current directory, it will be" -automatically loaded, else ~/.dosboxrc (if present) will be loaded. +Configuration and language files use a format similar to Windows .ini files. +First ~/.dosboxrc (if present) will be loaded. If no +configfile is specified at the commandline, a file named +.BR dosbox.conf " (if present in the current directory) will be" +loaded automatically afterwards. If a configfile is specified at the commandline +that one will be used instead. .SH "SPECIAL KEYS" .TP 12m .IP ALT\-ENTER diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index d02c0c62..69e12a93 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: sdlmain.cpp,v 1.121 2006-07-22 18:32:29 c2woody Exp $ */ +/* $Id: sdlmain.cpp,v 1.122 2006-10-08 19:26:04 qbix79 Exp $ */ #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -1423,24 +1423,22 @@ int main(int argc, char* argv[]) { /* Init all the dosbox subsystems */ DOSBOX_Init(); std::string config_file; - if (control->cmdline->FindString("-conf",config_file,true)) { - - } else { - config_file="dosbox.conf"; - } - /* Parse the config file - * try open config file in $HOME if can't open dosbox.conf or specified file - */ - if (control->ParseConfigFile(config_file.c_str()) == false) { - if ((getenv("HOME") != NULL)) { - config_file = (std::string)getenv("HOME") + - (std::string)DEFAULT_CONFIG_FILE; - if (control->ParseConfigFile(config_file.c_str()) == false) { - LOG_MSG("CONFIG: Using default settings. Create a configfile to change them"); - } - - } + bool parsed_anyconfigfile = false; + // First parse the configfile in the $HOME directory + if ((getenv("HOME") != NULL)) { + config_file = (std::string)getenv("HOME") + + (std::string)DEFAULT_CONFIG_FILE; + if (control->ParseConfigFile(config_file.c_str())) parsed_anyconfigfile = true; } + // Add extra settings from dosbox.conf in the local directory if there is no configfile specified at the commandline + if (!control->cmdline->FindString("-conf",config_file,true)) config_file="dosbox.conf"; + if (control->ParseConfigFile(config_file.c_str())) parsed_anyconfigfile = true; + // Add extra settings from additional configfiles at the commandline + while(control->cmdline->FindString("-conf",config_file,true)) + if (control->ParseConfigFile(config_file.c_str())) parsed_anyconfigfile = true; + // Give a message if no configfile whatsoever was found. + if(!parsed_anyconfigfile) LOG_MSG("CONFIG: Using default settings. Create a configfile to change them"); + #if (ENVIRON_LINKED) control->ParseEnv(environ); #endif diff --git a/src/misc/setup.cpp b/src/misc/setup.cpp index ea8a368c..b2850377 100644 --- a/src/misc/setup.cpp +++ b/src/misc/setup.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: setup.cpp,v 1.36 2006-05-25 15:07:33 qbix79 Exp $ */ +/* $Id: setup.cpp,v 1.37 2006-10-08 19:26:04 qbix79 Exp $ */ #include "dosbox.h" #include "cross.h" @@ -291,10 +291,14 @@ Section* Config::GetSectionFromProperty(char const * const prop) const{ } return NULL; } + bool Config::ParseConfigFile(char const * const configfilename){ + static bool first_configfile = true; ifstream in(configfilename); if (!in) return false; - LOG_MSG("CONFIG:Loading settings from config file %s", configfilename); + const char * settings_type = first_configfile?"primary":"additional"; + first_configfile = false; + LOG_MSG("CONFIG:Loading %s settings from config file %s", settings_type,configfilename); char gegevens[1024]; Section* currentsection = NULL; Section* testsec = NULL;