[Scummvm-cvs-logs] scummvm master -> 0a0258edcfe7622115ab7f5418f318f6c0f1c866

fingolfin max at quendi.de
Fri Jun 3 17:35:52 CEST 2011


This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b25fa194b3 GUI: Fix some comments
11bd6da595 SCI: Switch some char* to Common::String&
3cc2e5b927 COMMON: Access mac res fork via FSNode instead of StdioStream
0a0258edcf COMMON: Let Common::normalizePath normalize '..' in paths


Commit: b25fa194b32f4a9862f52c1b3b90aeabd43de544
    https://github.com/scummvm/scummvm/commit/b25fa194b32f4a9862f52c1b3b90aeabd43de544
Author: Max Horn (max at quendi.de)
Date: 2011-06-03T07:16:38-07:00

Commit Message:
GUI: Fix some comments

Changed paths:
    gui/console.h
    gui/debugger.h



diff --git a/gui/console.h b/gui/console.h
index 442047e..50a00a1 100644
--- a/gui/console.h
+++ b/gui/console.h
@@ -31,7 +31,7 @@ class ScrollBarWidget;
 /*
  FIXME #1: The console dialog code has some fundamental problems.
  First of, note the conflict between the (constant) value kCharsPerLine, and the
- (variable) value _pageWidth. Look a bit at the code get familiar with them,
+ (variable) value _pageWidth. Look a bit at the code to get familiar with them,
  then return...
  Now, why don't we just drop kCharsPerLine? Because of the problem of resizing!
  When the user changes the scaler, the console will get resized. If the dialog
@@ -47,7 +47,7 @@ class ScrollBarWidget;
  of making things like scrolling, drawing etc. more complicated.
 
  Either way, the current situation is bad, and we should resolve it one way
- or the other (and if you can think of a thirds, feel free to suggest it).
+ or the other (and if you can think of a third, feel free to suggest it).
 
 
 
diff --git a/gui/debugger.h b/gui/debugger.h
index 031e297..b74b0d6 100644
--- a/gui/debugger.h
+++ b/gui/debugger.h
@@ -69,7 +69,7 @@ protected:
 	typedef Common::Functor2<int, const char **, bool> Debuglet;
 
 	/**
-	 * Convenience macro that makes it either to register a method
+	 * Convenience macro that makes it easier to register a method
 	 * of a debugger subclass as a command.
 	 * Usage example:
 	 *   DCmd_Register("COMMAND", WRAP_METHOD(MyDebugger, MyCmd));


Commit: 11bd6da595247773155b6155beb795ea25456fa7
    https://github.com/scummvm/scummvm/commit/11bd6da595247773155b6155beb795ea25456fa7
Author: Max Horn (max at quendi.de)
Date: 2011-06-03T07:16:38-07:00

Commit Message:
SCI: Switch some char* to Common::String&

Changed paths:
  A engines/agi/preagi_mickey.o.kaitain.86539.cD93K5
    engines/sci/engine/kfile.cpp
    engines/sci/engine/state.cpp
    engines/sci/engine/workarounds.cpp
    engines/sci/sci.h



diff --git a/engines/agi/preagi_mickey.o.kaitain.86539.cD93K5 b/engines/agi/preagi_mickey.o.kaitain.86539.cD93K5
new file mode 100644
index 0000000..67c719a
Binary files /dev/null and b/engines/agi/preagi_mickey.o.kaitain.86539.cD93K5 differ
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index ee88d8a..8dc7836 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -100,7 +100,7 @@ enum {
 
 
 
-reg_t file_open(EngineState *s, const char *filename, int mode, bool unwrapFilename) {
+reg_t file_open(EngineState *s, const Common::String &filename, int mode, bool unwrapFilename) {
 	Common::String englishName = g_sci->getSciLanguageString(filename, K_LANG_ENGLISH);
 	Common::String wrappedName = unwrapFilename ? g_sci->wrapFilename(englishName) : englishName;
 	Common::SeekableReadStream *inFile = 0;
@@ -178,7 +178,7 @@ reg_t kFOpen(EngineState *s, int argc, reg_t *argv) {
 	int mode = argv[1].toUint16();
 
 	debugC(kDebugLevelFile, "kFOpen(%s,0x%x)", name.c_str(), mode);
-	return file_open(s, name.c_str(), mode, true);
+	return file_open(s, name, mode, true);
 }
 
 static FileHandle *getFileFromHandle(EngineState *s, uint handle) {
@@ -644,7 +644,7 @@ reg_t kSaveGame(EngineState *s, int argc, reg_t *argv) {
 	if (!out) {
 		warning("Error opening savegame \"%s\" for writing", filename.c_str());
 	} else {
-		if (!gamestate_save(s, out, game_description.c_str(), version.c_str())) {
+		if (!gamestate_save(s, out, game_description, version)) {
 			warning("Saving the game failed");
 		} else {
 			s->r_acc = TRUE_REG; // save successful
@@ -792,7 +792,7 @@ reg_t kFileIOOpen(EngineState *s, int argc, reg_t *argv) {
 		unwrapFilename = false;
 	}
 
-	return file_open(s, name.c_str(), mode, unwrapFilename);
+	return file_open(s, name, mode, unwrapFilename);
 }
 
 reg_t kFileIOClose(EngineState *s, int argc, reg_t *argv) {
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index e094ed3..3328f80 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -192,10 +192,10 @@ static kLanguage charToLanguage(const char c) {
 	}
 }
 
-Common::String SciEngine::getSciLanguageString(const char *str, kLanguage lang, kLanguage *lang2) const {
+Common::String SciEngine::getSciLanguageString(const Common::String &str, kLanguage lang, kLanguage *lang2) const {
 	kLanguage secondLang = K_LANG_NONE;
 
-	const char *seeker = str;
+	const char *seeker = str.c_str();
 	while (*seeker) {
 		if ((*seeker == '%') || (*seeker == '#')) {
 			secondLang = charToLanguage(*(seeker + 1));
@@ -242,9 +242,9 @@ Common::String SciEngine::getSciLanguageString(const char *str, kLanguage lang,
 	}
 
 	if (seeker)
-		return Common::String(str, seeker - str);
+		return Common::String(str.c_str(), seeker - str.c_str());
 	else
-		return Common::String(str);
+		return str;
 }
 
 kLanguage SciEngine::getSciLanguage() {
diff --git a/engines/sci/engine/workarounds.cpp b/engines/sci/engine/workarounds.cpp
index fa25b02..8bf90ff 100644
--- a/engines/sci/engine/workarounds.cpp
+++ b/engines/sci/engine/workarounds.cpp
@@ -447,7 +447,7 @@ SciWorkaroundSolution trackOriginAndFindWorkaround(int index, const SciWorkaroun
 			workaround = workaroundList;
 			while (workaround->methodName) {
 				bool objectNameMatches = (workaround->objectName == NULL) || 
-										 (workaround->objectName == g_sci->getSciLanguageString(searchObjectName.c_str(), K_LANG_ENGLISH));
+										 (workaround->objectName == g_sci->getSciLanguageString(searchObjectName, K_LANG_ENGLISH));
 
 				// Special case: in the fanmade Russian translation of SQ4, all
 				// of the object names have been deleted or renamed to Russian,
@@ -460,7 +460,7 @@ SciWorkaroundSolution trackOriginAndFindWorkaround(int index, const SciWorkaroun
 						&& ((workaround->roomNr == -1) || (workaround->roomNr == curRoomNumber))
 						&& ((workaround->inheritanceLevel == -1) || (workaround->inheritanceLevel == inheritanceLevel))
 						&& objectNameMatches
-						&& workaround->methodName == g_sci->getSciLanguageString(curMethodName.c_str(), K_LANG_ENGLISH)
+						&& workaround->methodName == g_sci->getSciLanguageString(curMethodName, K_LANG_ENGLISH)
 						&& workaround->localCallOffset == lastCall->debugLocalCallOffset
 						&& ((workaround->index == -1) || (workaround->index == index))) {
 					// Workaround found
diff --git a/engines/sci/sci.h b/engines/sci/sci.h
index 77718e4..04ccbd9 100644
--- a/engines/sci/sci.h
+++ b/engines/sci/sci.h
@@ -290,7 +290,7 @@ public:
 	void setSciLanguage(kLanguage lang);
 	void setSciLanguage();
 
-	Common::String getSciLanguageString(const char *str, kLanguage lang, kLanguage *lang2 = NULL) const;
+	Common::String getSciLanguageString(const Common::String &str, kLanguage lang, kLanguage *lang2 = NULL) const;
 
 	// Check if vocabulary needs to get switched (in multilingual parser games)
 	void checkVocabularySwitch();


Commit: 3cc2e5b9278e5f1ac846ff2a62c55361a69a8867
    https://github.com/scummvm/scummvm/commit/3cc2e5b9278e5f1ac846ff2a62c55361a69a8867
Author: Max Horn (max at quendi.de)
Date: 2011-06-03T08:30:30-07:00

Commit Message:
COMMON: Access mac res fork via FSNode instead of StdioStream

This fixes linker problems with the unit tests on Mac OS X. it is also
"more proper" to use the high-level FSNode API. StdioStream is a
(relatively) low-level wrapper intended for use inside of backends only.

Changed paths:
    common/macresman.cpp



diff --git a/common/macresman.cpp b/common/macresman.cpp
index 70c6e0a..6cbc08d 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -32,7 +32,6 @@
 
 #ifdef MACOSX
 #include "common/config-manager.h"
-#include "backends/fs/stdiostream.h"
 #endif
 
 namespace Common {
@@ -108,7 +107,7 @@ bool MacResManager::open(String filename) {
 #ifdef MACOSX
 	// Check the actual fork on a Mac computer
 	String fullPath = ConfMan.get("path") + "/" + filename + "/..namedfork/rsrc";
-	SeekableReadStream *macResForkRawStream = StdioStream::makeFromPath(fullPath, false);
+	SeekableReadStream *macResForkRawStream = FSNode(fullPath).createReadStream();;
 
 	if (macResForkRawStream && loadFromRawFork(*macResForkRawStream)) {
 		_baseFileName = filename;
@@ -168,7 +167,7 @@ bool MacResManager::open(FSNode path, String filename) {
 #ifdef MACOSX
 	// Check the actual fork on a Mac computer
 	String fullPath = path.getPath() + "/" + filename + "/..namedfork/rsrc";
-	SeekableReadStream *macResForkRawStream = StdioStream::makeFromPath(fullPath, false);
+	SeekableReadStream *macResForkRawStream = FSNode(fullPath).createReadStream();
 
 	if (macResForkRawStream && loadFromRawFork(*macResForkRawStream)) {
 		_baseFileName = filename;


Commit: 0a0258edcfe7622115ab7f5418f318f6c0f1c866
    https://github.com/scummvm/scummvm/commit/0a0258edcfe7622115ab7f5418f318f6c0f1c866
Author: Max Horn (max at quendi.de)
Date: 2011-06-03T08:33:07-07:00

Commit Message:
COMMON: Let Common::normalizePath normalize '..' in paths

There are some unit tests to verify that this works correctly.
There is a small chance that this causes regressions in weird setups.

Changed paths:
    common/str.cpp
    test/common/str.h



diff --git a/common/str.cpp b/common/str.cpp
index 740e7b6..223188b 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -19,11 +19,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "common/str.h"
 #include "common/hash-str.h"
-#include "common/util.h"
-
+#include "common/list.h"
 #include "common/memorypool.h"
+#include "common/str.h"
+#include "common/util.h"
 
 #include <stdarg.h>
 
@@ -256,7 +256,7 @@ String &String::operator=(char c) {
 
 String &String::operator+=(const char *str) {
 	if (_str <= str && str <= _str + _size)
-		return operator+=(Common::String(str));
+		return operator+=(String(str));
 
 	int len = strlen(str);
 	if (len > 0) {
@@ -270,7 +270,7 @@ String &String::operator+=(const char *str) {
 
 String &String::operator+=(const String &str) {
 	if (&str == this)
-		return operator+=(Common::String(str));
+		return operator+=(String(str));
 
 	int len = str._size;
 	if (len > 0) {
@@ -612,7 +612,7 @@ char *trim(char *t) {
 	return rtrim(ltrim(t));
 }
 
-Common::String lastPathComponent(const Common::String &path, const char sep) {
+String lastPathComponent(const String &path, const char sep) {
 	const char *str = path.c_str();
 	const char *last = str + path.size();
 
@@ -622,7 +622,7 @@ Common::String lastPathComponent(const Common::String &path, const char sep) {
 
 	// Path consisted of only slashes -> return empty string
 	if (last == str)
-		return Common::String();
+		return String();
 
 	// Now scan the whole component
 	const char *first = last - 1;
@@ -632,24 +632,26 @@ Common::String lastPathComponent(const Common::String &path, const char sep) {
 	if (*first == sep)
 		first++;
 
-	return Common::String(first, last);
+	return String(first, last);
 }
 
-Common::String normalizePath(const Common::String &path, const char sep) {
+String normalizePath(const String &path, const char sep) {
 	if (path.empty())
 		return path;
 
 	const char *cur = path.c_str();
-	Common::String result;
+	String result;
 
 	// If there is a leading slash, preserve that:
 	if (*cur == sep) {
 		result += sep;
+		// Skip over multiple leading slashes, so "//" equals "/"
 		while (*cur == sep)
 			++cur;
 	}
 
-	// Scan till the end of the String
+	// Scan for path components till the end of the String
+	List<String> comps;
 	while (*cur != 0) {
 		const char *start = cur;
 
@@ -657,18 +659,16 @@ Common::String normalizePath(const Common::String &path, const char sep) {
 		while (*cur != sep && *cur != 0)
 			cur++;
 
-		const Common::String component(start, cur);
-
-		// Skip empty components and dot components, add all others
-		if (!component.empty() && component != ".") {
-			// Add a separator before the component, unless the result
-			// string already ends with one (which happens only if the
-			// path *starts* with a separator).
-			if (!result.empty() && result.lastChar() != sep)
-				result += sep;
+		const String component(start, cur);
 
-			// Add the component
-			result += component;
+		if (component.empty() || component == ".") {
+			// Skip empty components and dot components
+		} else if (!comps.empty() && component == ".." && comps.back() != "..") {
+			// If stack is non-empty and top is not "..", remove top
+			comps.pop_back();
+		} else {
+			// Add the component to the stack
+			comps.push_back(component);
 		}
 
 		// Skip over separator chars
@@ -676,6 +676,14 @@ Common::String normalizePath(const Common::String &path, const char sep) {
 			cur++;
 	}
 
+	// Finally, assemble all components back into a path
+	while (!comps.empty()) {
+		result += comps.front();
+		comps.pop_front();
+		if (!comps.empty())
+			result += sep;
+	}
+
 	return result;
 }
 
@@ -749,7 +757,7 @@ String tag2string(uint32 tag) {
 		if (!isprint((unsigned char)str[i]))
 			str[i] = '.';
 	}
-	return Common::String(str);
+	return String(str);
 }
 
 size_t strlcpy(char *dst, const char *src, size_t size) {
diff --git a/test/common/str.h b/test/common/str.h
index 0dee16a..2c563f3 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -284,6 +284,19 @@ class StringTestSuite : public CxxTest::TestSuite
 		TS_ASSERT_EQUALS(Common::normalizePath("foo/./bar", '/'), "foo/bar");
 		TS_ASSERT_EQUALS(Common::normalizePath("foo//./bar//", '/'), "foo/bar");
 		TS_ASSERT_EQUALS(Common::normalizePath("foo//.bar//", '/'), "foo/.bar");
+
+		TS_ASSERT_EQUALS(Common::normalizePath("..", '/'), "..");
+		TS_ASSERT_EQUALS(Common::normalizePath("../", '/'), "..");
+		TS_ASSERT_EQUALS(Common::normalizePath("/..", '/'), "/..");
+		TS_ASSERT_EQUALS(Common::normalizePath("../bar", '/'), "../bar");
+		TS_ASSERT_EQUALS(Common::normalizePath("foo//../", '/'), "");
+		TS_ASSERT_EQUALS(Common::normalizePath("foo/../bar", '/'), "bar");
+		TS_ASSERT_EQUALS(Common::normalizePath("foo//../bar//", '/'), "bar");
+		TS_ASSERT_EQUALS(Common::normalizePath("foo//..bar//", '/'), "foo/..bar");
+
+		TS_ASSERT_EQUALS(Common::normalizePath("foo/../../bar//", '/'), "../bar");
+		TS_ASSERT_EQUALS(Common::normalizePath("../foo/../bar", '/'), "../bar");
+		TS_ASSERT_EQUALS(Common::normalizePath("../../foo/bar/", '/'), "../../foo/bar");
 	}
 
 	void test_matchString() {






More information about the Scummvm-git-logs mailing list