[Scummvm-cvs-logs] SF.net SVN: scummvm:[34318] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Wed Sep 3 20:40:51 CEST 2008
Revision: 34318
http://scummvm.svn.sourceforge.net/scummvm/?rev=34318&view=rev
Author: fingolfin
Date: 2008-09-03 18:40:49 +0000 (Wed, 03 Sep 2008)
Log Message:
-----------
Changed some code to use the new Stream::readLine() method
Modified Paths:
--------------
scummvm/trunk/common/config-file.cpp
scummvm/trunk/common/config-manager.cpp
scummvm/trunk/engines/parallaction/detection.cpp
Modified: scummvm/trunk/common/config-file.cpp
===================================================================
--- scummvm/trunk/common/config-file.cpp 2008-09-03 18:38:01 UTC (rev 34317)
+++ scummvm/trunk/common/config-file.cpp 2008-09-03 18:40:49 UTC (rev 34318)
@@ -77,7 +77,6 @@
}
bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
- char buf[MAXLINELEN];
Section section;
KeyValue kv;
String comment;
@@ -86,18 +85,21 @@
// 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 @@
// 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 @@
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));
+ // 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
+ // Skip empty lines / lines with only whitespace
if (*t == 0)
continue;
@@ -146,14 +150,20 @@
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);
- kv.key = rtrim(t);
- kv.value = ltrim(p + 1);
+ // Extract the key/value pair
+ kv.key = String(t, p);
+ kv.value = String(p + 1);
+
+ // Trim of spaces
+ kv.key.trim();
+ kv.value.trim();
+
+ // Store comment
kv.comment = comment;
comment.clear();
Modified: scummvm/trunk/common/config-manager.cpp
===================================================================
--- scummvm/trunk/common/config-manager.cpp 2008-09-03 18:38:01 UTC (rev 34317)
+++ scummvm/trunk/common/config-manager.cpp 2008-09-03 18:40:49 UTC (rev 34318)
@@ -103,13 +103,7 @@
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 @@
// 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;
Modified: scummvm/trunk/engines/parallaction/detection.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/detection.cpp 2008-09-03 18:38:01 UTC (rev 34317)
+++ scummvm/trunk/engines/parallaction/detection.cpp 2008-09-03 18:40:49 UTC (rev 34318)
@@ -278,7 +278,6 @@
SaveStateList ParallactionMetaEngine::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringList filenames;
- char saveDesc[200];
Common::String pattern = target;
pattern += ".0??";
@@ -293,7 +292,7 @@
if (slotNum >= 0 && slotNum <= 99) {
Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str());
if (in) {
- in->readLine_OLD(saveDesc, 199);
+ Common::String saveDesc = in->readLine();
saveList.push_back(SaveStateDescriptor(slotNum, saveDesc, *file));
delete in;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list