aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2008-09-03 18:40:49 +0000
committerMax Horn2008-09-03 18:40:49 +0000
commitad87f08192cd5ba129f83f6e50ed7b6f2113e075 (patch)
tree884ffe170fcc11de34451a006a68abc8d2a389d0 /common
parent3cb4cfa06ff10ac1f5b708ae78e624c07b3eaa4e (diff)
downloadscummvm-rg350-ad87f08192cd5ba129f83f6e50ed7b6f2113e075.tar.gz
scummvm-rg350-ad87f08192cd5ba129f83f6e50ed7b6f2113e075.tar.bz2
scummvm-rg350-ad87f08192cd5ba129f83f6e50ed7b6f2113e075.zip
Changed some code to use the new Stream::readLine() method
svn-id: r34318
Diffstat (limited to 'common')
-rw-r--r--common/config-file.cpp56
-rw-r--r--common/config-manager.cpp9
2 files changed, 35 insertions, 30 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp
index b01f759782..c3764a02da 100644
--- a/common/config-file.cpp
+++ b/common/config-file.cpp
@@ -77,7 +77,6 @@ bool ConfigFile::loadFromSaveFile(const char *filename) {
}
bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
- char buf[MAXLINELEN];
Section section;
KeyValue kv;
String comment;
@@ -86,18 +85,21 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
// TODO: Detect if a section occurs multiple times (or likewise, if
// a key occurs multiple times inside one section).
- while (!stream.eos()) {
+ while (!stream.eos() && !stream.ioFailed()) {
lineno++;
- if (!stream.readLine_OLD(buf, MAXLINELEN))
- break;
- if (buf[0] == '#') {
+ // Read a line
+ String line = stream.readLine();
+
+ if (line.size() == 0) {
+ // Do nothing
+ } else if (line[0] == '#') {
// Accumulate comments here. Once we encounter either the start
// of a new section, or a key-value-pair, we associate the value
// of the 'comment' variable with that entity.
- comment += buf;
+ comment += line;
comment += "\n";
- } else if (buf[0] == '(') {
+ } else if (line[0] == '(') {
// HACK: The following is a hack added by Kirben to support the
// "map.ini" used in the HE SCUMM game "SPY Fox in Hold the Mustard".
//
@@ -105,11 +107,11 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
// but the current design of this class doesn't allow to do that
// in a nice fashion (a "isMustard" parameter is *not* a nice
// solution).
- comment += buf;
+ comment += line;
comment += "\n";
- } else if (buf[0] == '[') {
+ } else if (line[0] == '[') {
// It's a new section which begins here.
- char *p = buf + 1;
+ const char *p = line.c_str() + 1;
// Get the section name, and check whether it's valid (that
// is, verify that it only consists of alphanumerics,
// dashes and underscores).
@@ -121,23 +123,25 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
else if (*p != ']')
error("ConfigFile::loadFromStream: Invalid character '%c' occured in section name in line %d", *p, lineno);
- *p = 0;
-
// Previous section is finished now, store it.
if (!section.name.empty())
_sections.push_back(section);
- section.name = buf + 1;
+ section.name = String(line.c_str() + 1, p);
section.keys.clear();
section.comment = comment;
comment.clear();
assert(isValidName(section.name));
} else {
- // Skip leading & trailing whitespaces
- char *t = rtrim(ltrim(buf));
-
- // Skip empty lines
+ // This line should be a line with a 'key=value' pair, or an empty one.
+
+ // Skip leading whitespaces
+ const char *t = line.c_str();
+ while (isspace(*t))
+ t++;
+
+ // Skip empty lines / lines with only whitespace
if (*t == 0)
continue;
@@ -146,14 +150,20 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
error("ConfigFile::loadFromStream: Key/value pair found outside a section in line %d", lineno);
}
- // Split string at '=' into 'key' and 'value'.
- char *p = strchr(t, '=');
+ // Split string at '=' into 'key' and 'value'. First, find the "=" delimeter.
+ const char *p = strchr(t, '=');
if (!p)
- error("ConfigFile::loadFromStream: Junk found in line line %d: '%s'", lineno, t);
- *p = 0;
+ error("Config file buggy: Junk found in line line %d: '%s'", lineno, t);
+
+ // Extract the key/value pair
+ kv.key = String(t, p);
+ kv.value = String(p + 1);
+
+ // Trim of spaces
+ kv.key.trim();
+ kv.value.trim();
- kv.key = rtrim(t);
- kv.value = ltrim(p + 1);
+ // Store comment
kv.comment = comment;
comment.clear();
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 138fcc201f..b741757cc5 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -103,13 +103,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) {
lineno++;
// Read a line
- String line;
- while (line.lastChar() != '\n') {
- char buf[256];
- if (!stream.readLine_NEW(buf, 256))
- break;
- line += buf;
- }
+ String line = stream.readLine();
if (line.size() == 0) {
// Do nothing
@@ -118,6 +112,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) {
// of a new domain, or a key-value-pair, we associate the value
// of the 'comment' variable with that entity.
comment += line;
+ comment += "\n";
} else if (line[0] == '[') {
// It's a new domain which begins here.
const char *p = line.c_str() + 1;