aboutsummaryrefslogtreecommitdiff
path: root/common/config-manager.cpp
diff options
context:
space:
mode:
authorMax Horn2003-10-10 11:13:25 +0000
committerMax Horn2003-10-10 11:13:25 +0000
commit2dddd0e29a148949148b830f298b3479b4a3b9bc (patch)
tree2c10af6202e654928a50a6293645f27bf3bb2590 /common/config-manager.cpp
parenteece292342f641dbb394496feed3fc7a3d6782f1 (diff)
downloadscummvm-rg350-2dddd0e29a148949148b830f298b3479b4a3b9bc.tar.gz
scummvm-rg350-2dddd0e29a148949148b830f298b3479b4a3b9bc.tar.bz2
scummvm-rg350-2dddd0e29a148949148b830f298b3479b4a3b9bc.zip
modified version of patch #821018; fix for bug #821083
svn-id: r10716
Diffstat (limited to 'common/config-manager.cpp')
-rw-r--r--common/config-manager.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index bf9121bedd..8e6bd06504 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -51,7 +51,6 @@ static char *rtrim(char *t) {
return t;
}
-
namespace Common {
const String ConfigManager::kApplicationDomain("scummvm");
@@ -98,16 +97,18 @@ ConfigManager::ConfigManager() {
void ConfigManager::loadFile(const String &filename) {
FILE *cfg_file;
- char t[MAXLINELEN];
+ char buf[MAXLINELEN];
+ char *t;
String domain;
if (!(cfg_file = fopen(filename.c_str(), "r"))) {
debug(1, "Unable to open configuration file: %s.\n", filename.c_str());
} else {
while (!feof(cfg_file)) {
+ t = buf;
if (!fgets(t, MAXLINELEN, cfg_file))
continue;
- if (t[0] != '#') {
+ if (t[0] && t[0] != '#') {
if (t[0] == '[') {
// It's a new domain which begins here.
char *p = strchr(t, ']');
@@ -120,10 +121,20 @@ void ConfigManager::loadFile(const String &filename) {
domain = t + 1;
}
} else {
- // It's a new key in the domain.
+ // Skip leading whitespaces
+ while (*t && isspace(*t)) {
+ t++;
+ }
+ // Skip empty lines
+ if (*t == 0)
+ continue;
+
+ // If no domain has been set, this config file is invalid!
if (domain.isEmpty()) {
error("Config file buggy: we have a key without a domain first.\n");
}
+
+ // It's a new key in the domain.
char *p = strchr(t, '\n');
if (p)
*p = 0;
@@ -299,8 +310,10 @@ void ConfigManager::set(const String &key, const String &value) {
}
void ConfigManager::set(const String &key, const String &value, const String &dom) {
- if (dom.isEmpty())
+ if (dom.isEmpty()) {
set(key, value);
+ return;
+ }
if (_globalDomains.contains(dom))
_globalDomains[dom][key] = value;