[Scummvm-git-logs] scummvm master -> 9bbd0474fab672ff843caf40305475f856b30f74
dreammaster
paulfgilbert at gmail.com
Tue Jan 1 09:58:52 CET 2019
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
0d1f5bc2d0 GLK: Fix gcc warning in engine construction
7643382ff4 COMMON: Suport String in U32String assignment & equality operators
9bbd0474fa GLK: FROTZ: Support shorthand abbreviations in earlier Infocom games
Commit: 0d1f5bc2d0c828165abd422a2e0a47ad3d9ae8c9
https://github.com/scummvm/scummvm/commit/0d1f5bc2d0c828165abd422a2e0a47ad3d9ae8c9
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-01-01T00:38:49-08:00
Commit Message:
GLK: Fix gcc warning in engine construction
Changed paths:
engines/glk/detection.cpp
diff --git a/engines/glk/detection.cpp b/engines/glk/detection.cpp
index 4c0932a..1b8ed59 100644
--- a/engines/glk/detection.cpp
+++ b/engines/glk/detection.cpp
@@ -73,8 +73,6 @@ template<class META, class ENG>Engine *create(OSystem *syst, Glk::GlkGameDescrip
}
}
-#define CREATE(META, ENG) if (!(*engine = create<META, ENG>(syst, gameDesc)))
-
Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
Glk::GameDescriptor td = Glk::GameDescriptor::empty();
assert(engine);
@@ -108,11 +106,12 @@ Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) cons
f.close();
// Create the correct engine
- CREATE(Glk::Alan2::Alan2MetaEngine, Glk::Alan2::Alan2)
- CREATE(Glk::Frotz::FrotzMetaEngine, Glk::Frotz::Frotz)
- CREATE(Glk::Glulxe::GlulxeMetaEngine, Glk::Glulxe::Glulxe)
- CREATE(Glk::Scott::ScottMetaEngine, Glk::Scott::Scott)
- if (!((td = Glk::TADS::TADSMetaEngine::findGame(gameDesc._gameId.c_str()))._description)) {
+ *engine = nullptr;
+ if ((*engine = create<Glk::Alan2::Alan2MetaEngine, Glk::Alan2::Alan2>(syst, gameDesc)) != nullptr) {}
+ else if ((*engine = create<Glk::Frotz::FrotzMetaEngine, Glk::Frotz::Frotz>(syst, gameDesc)) != nullptr) {}
+ else if ((*engine = create<Glk::Glulxe::GlulxeMetaEngine, Glk::Glulxe::Glulxe>(syst, gameDesc)) != nullptr) {}
+ else if ((*engine = create<Glk::Scott::ScottMetaEngine, Glk::Scott::Scott>(syst, gameDesc)) != nullptr) {}
+ else if ((td = Glk::TADS::TADSMetaEngine::findGame(gameDesc._gameId.c_str()))._description) {
if (td._options & Glk::TADS::OPTION_TADS3)
*engine = new Glk::TADS::TADS3::TADS3(syst, gameDesc);
else
@@ -124,8 +123,6 @@ Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) cons
return Common::kNoError;
}
-#undef CREATE
-
Common::String GlkMetaEngine::findFileByGameId(const Common::String &gameId) const {
// Get the list of files in the folder and return detection against them
Common::FSNode folder = Common::FSNode(ConfMan.get("path"));
Commit: 7643382ff4c19bf69ac36c015ca9e8e046c20c77
https://github.com/scummvm/scummvm/commit/7643382ff4c19bf69ac36c015ca9e8e046c20c77
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-01-01T00:40:17-08:00
Commit Message:
COMMON: Suport String in U32String assignment & equality operators
Changed paths:
common/ustr.cpp
common/ustr.h
diff --git a/common/ustr.cpp b/common/ustr.cpp
index ecc91bb..7f68f8a 100644
--- a/common/ustr.cpp
+++ b/common/ustr.cpp
@@ -72,6 +72,28 @@ U32String::U32String(const U32String &str)
assert(_str != nullptr);
}
+U32String::U32String(const char *str) : _size(0), _str(_storage) {
+ if (str == nullptr) {
+ _storage[0] = 0;
+ _size = 0;
+ } else {
+ initWithCStr(str, strlen(str));
+ }
+}
+
+U32String::U32String(const char *str, uint32 len) : _size(0), _str(_storage) {
+ initWithCStr(str, len);
+}
+
+U32String::U32String(const char *beginP, const char *endP) : _size(0), _str(_storage) {
+ assert(endP >= beginP);
+ initWithCStr(beginP, endP - beginP);
+}
+
+U32String::U32String(const String &str) : _size(0) {
+ initWithCStr(str.c_str(), str.size());
+}
+
U32String::~U32String() {
decRefCount(_extern._refCount);
}
@@ -98,6 +120,20 @@ U32String &U32String::operator=(const U32String &str) {
return *this;
}
+U32String &U32String::operator=(const String &str) {
+ initWithCStr(str.c_str(), str.size());
+ return *this;
+}
+
+U32String &U32String::operator=(const value_type *str) {
+ return U32String::operator=(U32String(str));
+}
+
+U32String &U32String::operator=(const char *str) {
+ initWithCStr(str, strlen(str));
+ return *this;
+}
+
U32String &U32String::operator+=(const U32String &str) {
if (&str == this) {
return operator+=(U32String(str));
@@ -122,6 +158,38 @@ U32String &U32String::operator+=(value_type c) {
return *this;
}
+bool U32String::operator==(const U32String &x) const {
+ return equals(x);
+}
+
+bool U32String::operator==(const String &x) const {
+ return equals(x);
+}
+
+bool U32String::operator==(const value_type *x) const {
+ return equals(U32String(x));
+}
+
+bool U32String::operator==(const char *x) const {
+ return equals(x);
+}
+
+bool U32String::operator!=(const U32String &x) const {
+ return !equals(x);
+}
+
+bool U32String::operator!=(const String &x) const {
+ return !equals(x);
+}
+
+bool U32String::operator!=(const value_type *x) const {
+ return !equals(U32String(x));
+}
+
+bool U32String::operator!=(const char *x) const {
+ return !equals(x);
+}
+
bool U32String::equals(const U32String &x) const {
if (this == &x || _str == x._str) {
return true;
@@ -134,6 +202,17 @@ bool U32String::equals(const U32String &x) const {
return !memcmp(_str, x._str, _size * sizeof(value_type));
}
+bool U32String::equals(const String &x) const {
+ if (x.size() != _size)
+ return false;
+
+ for (size_t idx = 0; idx < _size; ++idx)
+ if (_str[idx] != x[idx])
+ return false;
+
+ return true;
+}
+
bool U32String::contains(value_type x) const {
for (uint32 i = 0; i < _size; ++i) {
if (_str[i] == x) {
@@ -327,6 +406,28 @@ void U32String::initWithCStr(const value_type *str, uint32 len) {
_str[len] = 0;
}
+void U32String::initWithCStr(const char *str, uint32 len) {
+ assert(str);
+
+ _storage[0] = 0;
+
+ _size = len;
+
+ if (len >= _builtinCapacity) {
+ // Not enough internal storage, so allocate more
+ _extern._capacity = computeCapacity(len + 1);
+ _extern._refCount = nullptr;
+ _str = new value_type[_extern._capacity];
+ assert(_str != nullptr);
+ }
+
+ // Copy the string into the storage area
+ for (size_t idx = 0; idx < len; ++idx, ++str)
+ _str[idx] = *str;
+
+ _str[len] = 0;
+}
+
// This is a quick and dirty converter.
//
// More comprehensive one lives in wintermute/utils/convert_utf.cpp
diff --git a/common/ustr.h b/common/ustr.h
index d5e8f829..7f20207 100644
--- a/common/ustr.h
+++ b/common/ustr.h
@@ -102,23 +102,46 @@ public:
/** Construct a copy of the given string. */
U32String(const U32String &str);
+ /** Construct a new string from the given NULL-terminated C string. */
+ explicit U32String(const char *str);
+
+ /** Construct a new string containing exactly len characters read from address str. */
+ U32String(const char *str, uint32 len);
+
+ /** Construct a new string containing the characters between beginP (including) and endP (excluding). */
+ U32String(const char *beginP, const char *endP);
+
+ /** Construct a copy of the given string. */
+ U32String(const String &str);
+
~U32String();
U32String &operator=(const U32String &str);
+ U32String &operator=(const String &str);
+ U32String &operator=(const value_type *str);
+ U32String &operator=(const char *str);
U32String &operator+=(const U32String &str);
U32String &operator+=(value_type c);
+ bool operator==(const U32String &x) const;
+ bool operator==(const String &x) const;
+ bool operator==(const value_type *x) const;
+ bool operator==(const char *x) const;
+ bool operator!=(const U32String &x) const;
+ bool operator!=(const String &x) const;
+ bool operator!=(const value_type *x) const;
+ bool operator!=(const char *x) const;
/**
- * Equivalence comparison operator.
- * @see equals
+ * Compares whether two U32String are the same based on memory comparison.
+ * This does *not* do comparison based on canonical equivalence.
*/
- bool operator==(const U32String &x) const { return equals(x); }
+ bool equals(const U32String &x) const;
/**
* Compares whether two U32String are the same based on memory comparison.
* This does *not* do comparison based on canonical equivalence.
*/
- bool equals(const U32String &x) const;
+ bool equals(const String &x) const;
bool contains(value_type x) const;
@@ -191,6 +214,7 @@ private:
void incRefCount() const;
void decRefCount(int *oldRefCount);
void initWithCStr(const value_type *str, uint32 len);
+ void initWithCStr(const char *str, uint32 len);
};
U32String convertUtf8ToUtf32(const String &str);
Commit: 9bbd0474fab672ff843caf40305475f856b30f74
https://github.com/scummvm/scummvm/commit/9bbd0474fab672ff843caf40305475f856b30f74
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-01-01T00:56:42-08:00
Commit Message:
GLK: FROTZ: Support shorthand abbreviations in earlier Infocom games
Changed paths:
engines/glk/frotz/frotz.cpp
engines/glk/frotz/processor.h
engines/glk/frotz/processor_text.cpp
diff --git a/engines/glk/frotz/frotz.cpp b/engines/glk/frotz/frotz.cpp
index 3d6bf6c..c2341d4 100644
--- a/engines/glk/frotz/frotz.cpp
+++ b/engines/glk/frotz/frotz.cpp
@@ -48,8 +48,6 @@ void Frotz::runGame(Common::SeekableReadStream *gameFile) {
story_fp = gameFile;
initialize();
- debug("Game %s an Infocom original", isInfocom() ? "is" : "isn't");
-
// If save was selected from the launcher, handle loading it
int saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
if (saveSlot != -1) {
diff --git a/engines/glk/frotz/processor.h b/engines/glk/frotz/processor.h
index 5b9926b..83d2443 100644
--- a/engines/glk/frotz/processor.h
+++ b/engines/glk/frotz/processor.h
@@ -630,8 +630,12 @@ protected:
zword lookup_text(int padding, zword dct);
/**
- * tokenise_text
- *
+ * Handles converting abbreviations that weren't handled by early Infocom games
+ * into their expanded versions
+ */
+ void handleAbbreviations();
+
+ /**
* Translate a single word to a token and append it to the token
* buffer. Every token consists of the address of the dictionary
* entry, the length of the word and the offset of the word from
diff --git a/engines/glk/frotz/processor_text.cpp b/engines/glk/frotz/processor_text.cpp
index 32625f6..2b82f29 100644
--- a/engines/glk/frotz/processor_text.cpp
+++ b/engines/glk/frotz/processor_text.cpp
@@ -21,6 +21,7 @@
*/
#include "glk/frotz/processor.h"
+#include "common/ustr.h"
namespace Glk {
namespace Frotz {
@@ -192,7 +193,7 @@ void Processor::find_resolution() {
_encoded = (zchar *)malloc(sizeof(zchar) * _resolution);
}
-void Processor::load_string (zword addr, zword length) {
+void Processor::load_string(zword addr, zword length) {
int i = 0;
if (_resolution == 0)
@@ -560,6 +561,29 @@ zword Processor::lookup_text(int padding, zword dct) {
return dct + entry_number * entry_len;
}
+void Processor::handleAbbreviations() {
+ // Construct a unicode string containing the word
+ int wordSize = 0;
+ while (wordSize < (_resolution * 3) && _decoded[wordSize])
+ ++wordSize;
+ Common::U32String word(_decoded, _decoded + wordSize);
+
+ // Check for standard abbreviations
+ if (word == "g")
+ word == "again";
+ else if (word == "o")
+ word = "oops";
+ else if (word == "x")
+ word = "examine";
+ else if (word == "z")
+ word = "wait";
+ else
+ return;
+
+ // Found abbreviation, so copy it's long form into buffer
+ Common::copy(word.c_str(), word.c_str() + MIN((int)word.size() + 1, _resolution * 3), _decoded);
+}
+
void Processor::tokenise_text(zword text, zword length, zword from, zword parse, zword dct, bool flag) {
zword addr;
zbyte token_max, token_count;
@@ -574,6 +598,9 @@ void Processor::tokenise_text(zword text, zword length, zword from, zword parse,
load_string((zword)(text + from), length);
+ if ((from == 1) && isInfocom() && h_version < 5)
+ handleAbbreviations();
+
addr = lookup_text(0x05, dct);
if (addr != 0 || !flag) {
More information about the Scummvm-git-logs
mailing list