1
0
Fork 0

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
This commit is contained in:
Peter Veenstra 2006-10-08 19:26:04 +00:00
parent 6448f2a398
commit 54b29e831c
4 changed files with 36 additions and 27 deletions

View file

@ -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

View file

@ -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;