aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/algorithm.h8
-rw-r--r--common/config-manager.cpp14
-rw-r--r--common/debug.cpp30
-rw-r--r--common/debug.h19
-rw-r--r--common/forbidden.h161
-rw-r--r--common/hashmap.cpp4
-rw-r--r--common/hashmap.h38
-rw-r--r--common/macresman.cpp56
-rw-r--r--common/macresman.h42
-rw-r--r--common/md5.cpp28
-rw-r--r--common/md5.h31
-rw-r--r--common/memorypool.cpp2
-rw-r--r--common/memorypool.h2
-rw-r--r--common/mutex.h4
-rw-r--r--common/ptr.h3
-rw-r--r--common/scummsys.h8
-rw-r--r--common/str.cpp2
-rw-r--r--common/str.h2
-rw-r--r--common/textconsole.cpp9
-rw-r--r--common/timer.h1
-rw-r--r--common/unzip.cpp2
-rw-r--r--common/util.cpp28
-rw-r--r--common/util.h14
-rw-r--r--common/xmlparser.cpp97
-rw-r--r--common/xmlparser.h100
25 files changed, 459 insertions, 246 deletions
diff --git a/common/algorithm.h b/common/algorithm.h
index 9d22af4090..b34d6f852d 100644
--- a/common/algorithm.h
+++ b/common/algorithm.h
@@ -242,13 +242,17 @@ void sort(T first, T last) {
*/
template<class T>
T gcd(T a, T b) {
- if (a <= 0) a = -a;
- if (b <= 0) b = -b;
+ if (a <= 0)
+ a = -a;
+ if (b <= 0)
+ b = -b;
+
while (a > 0) {
T tmp = a;
a = b % a;
b = tmp;
}
+
return b;
}
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 554a99ea95..ec9fcaee6a 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -69,7 +69,7 @@ void ConfigManager::loadDefaultConfigFile() {
} else {
// No config file -> create new one!
- printf("Default configuration file missing, creating a new one\n");
+ debug("Default configuration file missing, creating a new one");
flushToDisk();
}
@@ -81,9 +81,9 @@ void ConfigManager::loadConfigFile(const String &filename) {
FSNode node(filename);
File cfg_file;
if (!cfg_file.open(node)) {
- printf("Creating configuration file: %s\n", filename.c_str());
+ debug("Creating configuration file: %s\n", filename.c_str());
} else {
- printf("Using configuration file: %s\n", _filename.c_str());
+ debug("Using configuration file: %s\n", _filename.c_str());
loadFromStream(cfg_file);
}
}
@@ -508,9 +508,7 @@ void ConfigManager::set(const String &key, const String &value, const String &do
}
void ConfigManager::setInt(const String &key, int value, const String &domName) {
- char tmp[128];
- snprintf(tmp, sizeof(tmp), "%i", value);
- set(key, String(tmp), domName);
+ set(key, String::format("%i", value), domName);
}
void ConfigManager::setBool(const String &key, bool value, const String &domName) {
@@ -530,9 +528,7 @@ void ConfigManager::registerDefault(const String &key, const char *value) {
}
void ConfigManager::registerDefault(const String &key, int value) {
- char tmp[128];
- snprintf(tmp, sizeof(tmp), "%i", value);
- registerDefault(key, tmp);
+ registerDefault(key, String::format("%i", value));
}
void ConfigManager::registerDefault(const String &key, bool value) {
diff --git a/common/debug.cpp b/common/debug.cpp
index 116c0d0d56..46f8e8b829 100644
--- a/common/debug.cpp
+++ b/common/debug.cpp
@@ -22,6 +22,10 @@
* $Id$
*/
+// Disable symbol overrides so that we can use system headers.
+// FIXME: Necessary for the PS2 port, should get rid of this eventually.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
#include "common/debug.h"
#include "common/debug-channels.h"
#include "common/util.h"
@@ -119,31 +123,15 @@ bool DebugManager::isDebugChannelEnabled(uint32 channel) {
return (gDebugChannelsEnabled & channel) != 0;
}
-
-
-static OutputFormatter s_debugOutputFormatter = 0;
-
-void setDebugOutputFormatter(OutputFormatter f) {
- s_debugOutputFormatter = f;
-}
-
} // End of namespace Common
#ifndef DISABLE_TEXT_CONSOLE
static void debugHelper(const char *s, va_list va, bool caret = true) {
- char in_buf[STRINGBUFLEN];
char buf[STRINGBUFLEN];
- vsnprintf(in_buf, STRINGBUFLEN, s, va);
- // Next, give the active engine (if any) a chance to augment the message,
- // but only if not used from debugN.
- if (caret && Common::s_debugOutputFormatter) {
- (*Common::s_debugOutputFormatter)(buf, in_buf, STRINGBUFLEN);
- } else {
- strncpy(buf, in_buf, STRINGBUFLEN);
- }
+ vsnprintf(buf, STRINGBUFLEN, s, va);
buf[STRINGBUFLEN-1] = '\0';
if (caret) {
@@ -186,6 +174,14 @@ void debug(int level, const char *s, ...) {
}
+void debugN(const char *s, ...) {
+ va_list va;
+
+ va_start(va, s);
+ debugHelper(s, va, false);
+ va_end(va);
+}
+
void debugN(int level, const char *s, ...) {
va_list va;
diff --git a/common/debug.h b/common/debug.h
index 2068a1314a..03de7f4f77 100644
--- a/common/debug.h
+++ b/common/debug.h
@@ -26,23 +26,12 @@
#define COMMON_DEBUG_H
#include "common/scummsys.h"
-#include "common/textconsole.h"
-
-namespace Common {
-
-/**
- * Set the output formatter used by debug() and related functions.
- */
-void setDebugOutputFormatter(OutputFormatter f);
-
-
-} // End of namespace Common
-
#ifdef DISABLE_TEXT_CONSOLE
inline void debug(const char *s, ...) {}
inline void debug(int level, const char *s, ...) {}
+inline void debugN(const char *s, ...) {}
inline void debugN(int level, const char *s, ...) {}
inline void debugC(int level, uint32 engineChannel, const char *s, ...) {}
inline void debugC(uint32 engineChannel, const char *s, ...) {}
@@ -68,6 +57,12 @@ void debug(const char *s, ...) GCC_PRINTF(1, 2);
void debug(int level, const char *s, ...) GCC_PRINTF(2, 3);
/**
+ * Print a debug message to the text console (stdout).
+ * Does not append a newline.
+ */
+void debugN(const char *s, ...) GCC_PRINTF(1, 2);
+
+/**
* Print a debug message to the text console (stdout), but only if
* the gDebugLevel equals at least the specified level.
* As a rule of thumb, the more important the message, the lower the level.
diff --git a/common/forbidden.h b/common/forbidden.h
new file mode 100644
index 0000000000..92e662ccc6
--- /dev/null
+++ b/common/forbidden.h
@@ -0,0 +1,161 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef COMMON_FORBIDDEN_H
+#define COMMON_FORBIDDEN_H
+
+/**
+ * @file
+ * This header file is meant to help ensure that engines and
+ * infrastructure code do not make use of certain "forbidden" APIs, such
+ * as fopen(), setjmp(), etc.
+ * This is achieved by re-#defining various symbols to a "garbage"
+ * string which then trigers a compiler error.
+ *
+ * Backend files may #define FORBIDDEN_SYMBOL_ALLOW_ALL if they
+ * have to access functions like fopen, fread etc.
+ * Regular code, esp. code in engines/, should never do that.
+ */
+
+#ifndef FORBIDDEN_SYMBOL_ALLOW_ALL
+
+/**
+ * The garbage string to use as replacement for forbidden symbols.
+ *
+ * The reason for this particular string is the following:
+ * By including a space and "!" we try to ensure a compiler error.
+ * By using the words "forbidden symbol" we try to make it a bit
+ * clearer what is causing the error.
+ */
+#define FORBIDDEN_SYMBOL_REPLACEMENT FORBIDDEN SYMBOL!
+
+
+/*
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_printf
+#undef printf
+#define printf FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fprintf
+#undef fprintf
+#define fprintf FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+*/
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_FILE
+#undef FILE
+#define FILE FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fopen
+#undef fopen
+#define fopen(a,b) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fclose
+#undef fclose
+#define fclose(a) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fread
+#undef fread
+#define fread(a,b,c,d) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fwrite
+#undef fwrite
+#define fwrite(a,b,c,d) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fseek
+#undef fseek
+#define fseek(a,b,c) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_ftell
+#undef ftell
+#define ftell(a) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_feof
+#undef feof
+#define feof(a) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fgetc
+#undef fgetc
+#define fgetc(a) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fputc
+#undef fputc
+#define fputc(a,b) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp
+#undef setjmp
+#define setjmp(a) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp
+#undef longjmp
+#define longjmp(a,b) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_system
+#undef system
+#define system(a) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+
+/*
+time_t
+
+time
+
+difftime
+
+mktime
+
+localtime
+
+clock
+
+gmtime
+
+system
+
+remove
+
+setlocale
+
+setvbuf
+*/
+
+#endif
+
+
+#endif
diff --git a/common/hashmap.cpp b/common/hashmap.cpp
index d8b84f61a5..5fe18f33ee 100644
--- a/common/hashmap.cpp
+++ b/common/hashmap.cpp
@@ -89,7 +89,7 @@ void updateHashCollisionStats(int collisions, int dummyHits, int lookups, int ar
g_max_capacity = MAX(g_max_capacity, arrsize);
g_max_size = MAX(g_max_size, nele);
- fprintf(stdout, "%d hashmaps: colls %.1f; dummies hit %.1f, lookups %.1f; ratio %.3f%%; size %f (max: %d); capacity %f (max: %d)\n",
+ debug("%d hashmaps: colls %.1f; dummies hit %.1f, lookups %.1f; ratio %.3f%%; size %f (max: %d); capacity %f (max: %d)",
g_totalHashmaps,
g_collisions / g_totalHashmaps,
g_dummyHits / g_totalHashmaps,
@@ -97,7 +97,7 @@ void updateHashCollisionStats(int collisions, int dummyHits, int lookups, int ar
100 * g_collPerLook / g_totalHashmaps,
g_size / g_totalHashmaps, g_max_size,
g_capacity / g_totalHashmaps, g_max_capacity);
- fprintf(stdout, " %d less than %d; %d less than %d; %d less than %d; %d less than %d\n",
+ debug(" %d less than %d; %d less than %d; %d less than %d; %d less than %d",
g_stats[0], 2*8/3,
g_stats[1],2*16/3,
g_stats[2],2*32/3,
diff --git a/common/hashmap.h b/common/hashmap.h
index 0d4d7663f3..81a136f671 100644
--- a/common/hashmap.h
+++ b/common/hashmap.h
@@ -29,28 +29,46 @@
#ifndef COMMON_HASHMAP_H
#define COMMON_HASHMAP_H
+/**
+ * @def DEBUG_HASH_COLLISIONS
+ * Enable the following #define if you want to check how many collisions the
+ * code produces (many collisions indicate either a bad hash function, or a
+ * hash table that is too small).
+ */
+//#define DEBUG_HASH_COLLISIONS
+
+/**
+ * @def USE_HASHMAP_MEMORY_POOL
+ * Enable the following define to let HashMaps use a memory pool for the
+ nodes they contain. * This increases memory usage, but also can improve
+ speed quite a bit.
+ */
+#define USE_HASHMAP_MEMORY_POOL
+
+
#include "common/func.h"
#include "common/str.h"
#include "common/util.h"
-#define USE_HASHMAP_MEMORY_POOL
+#ifdef DEBUG_HASH_COLLISIONS
+#include "common/debug.h"
+#endif
+
#ifdef USE_HASHMAP_MEMORY_POOL
#include "common/memorypool.h"
#endif
+
+
namespace Common {
// The sgi IRIX MIPSpro Compiler has difficulties with nested templates.
// This and the other __sgi conditionals below work around these problems.
-#if defined(__sgi) && !defined(__GNUC__)
+// The Intel C++ Compiler suffers from the same problems.
+#if (defined(__sgi) && !defined(__GNUC__)) || defined(__INTEL_COMPILER)
template<class T> class IteratorImpl;
#endif
-// Enable the following #define if you want to check how many collisions the
-// code produces (many collisions indicate either a bad hash function, or a
-// hash table that is too small).
-//#define DEBUG_HASH_COLLISIONS
-
/**
* HashMap<Key,Val> maps objects of type Key to objects of type Val.
@@ -138,7 +156,7 @@ private:
template<class NodeType>
class IteratorImpl {
friend class HashMap;
-#if defined(__sgi) && !defined(__GNUC__)
+#if (defined(__sgi) && !defined(__GNUC__)) || defined(__INTEL_COMPILER)
template<class T> friend class Common::IteratorImpl;
#else
template<class T> friend class IteratorImpl;
@@ -459,7 +477,7 @@ int HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const {
#ifdef DEBUG_HASH_COLLISIONS
_lookups++;
- fprintf(stderr, "collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d\n",
+ debug("collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d",
_collisions, _dummyHits, _lookups, ((double) _collisions / (double)_lookups),
(const void *)this, _mask+1, _size);
#endif
@@ -497,7 +515,7 @@ int HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key &
#ifdef DEBUG_HASH_COLLISIONS
_lookups++;
- fprintf(stderr, "collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d\n",
+ debug("collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d",
_collisions, _dummyHits, _lookups, ((double) _collisions / (double)_lookups),
(const void *)this, _mask+1, _size);
#endif
diff --git a/common/macresman.cpp b/common/macresman.cpp
index 641702b5ec..22216763b8 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -73,38 +73,36 @@ void MacResManager::close() {
delete _stream; _stream = 0;
}
-bool MacResManager::hasDataFork() {
+bool MacResManager::hasDataFork() const {
return !_baseFileName.empty();
}
-bool MacResManager::hasResFork() {
+bool MacResManager::hasResFork() const {
return !_baseFileName.empty() && _mode != kResForkNone;
}
-uint32 MacResManager::getResForkSize() {
+uint32 MacResManager::getResForkSize() const {
if (!hasResFork())
return 0;
return _resForkSize;
}
-bool MacResManager::getResForkMD5(char *md5str, uint32 length) {
+String MacResManager::computeResForkMD5AsString(uint32 length) const {
if (!hasResFork())
- return false;
+ return String();
- ReadStream *stream = new SeekableSubReadStream(_stream, _resForkOffset, _resForkOffset + _resForkSize);
- bool retVal = md5_file_string(*stream, md5str, MIN<uint32>(length, _resForkSize));
- delete stream;
- return retVal;
+ SeekableSubReadStream resForkStream(_stream, _resForkOffset, _resForkOffset + _resForkSize);
+ return computeStreamMD5AsString(resForkStream, MIN<uint32>(length, _resForkSize));
}
-bool MacResManager::open(Common::String filename) {
+bool MacResManager::open(String filename) {
close();
#ifdef MACOSX
// Check the actual fork on a Mac computer
- Common::String fullPath = ConfMan.get("path") + "/" + filename + "/..namedfork/rsrc";
- Common::SeekableReadStream *macResForkRawStream = StdioStream::makeFromPath(fullPath, false);
+ String fullPath = ConfMan.get("path") + "/" + filename + "/..namedfork/rsrc";
+ SeekableReadStream *macResForkRawStream = StdioStream::makeFromPath(fullPath, false);
if (macResForkRawStream && loadFromRawFork(*macResForkRawStream)) {
_baseFileName = filename;
@@ -114,7 +112,7 @@ bool MacResManager::open(Common::String filename) {
delete macResForkRawStream;
#endif
- Common::File *file = new Common::File();
+ File *file = new File();
// First, let's try to see if the Mac converted name exists
if (file->open("._" + filename) && loadFromAppleDouble(*file)) {
@@ -158,13 +156,13 @@ bool MacResManager::open(Common::String filename) {
return false;
}
-bool MacResManager::open(Common::FSNode path, Common::String filename) {
+bool MacResManager::open(FSNode path, String filename) {
close();
#ifdef MACOSX
// Check the actual fork on a Mac computer
- Common::String fullPath = path.getPath() + "/" + filename + "/..namedfork/rsrc";
- Common::SeekableReadStream *macResForkRawStream = StdioStream::makeFromPath(fullPath, false);
+ String fullPath = path.getPath() + "/" + filename + "/..namedfork/rsrc";
+ SeekableReadStream *macResForkRawStream = StdioStream::makeFromPath(fullPath, false);
if (macResForkRawStream && loadFromRawFork(*macResForkRawStream)) {
_baseFileName = filename;
@@ -175,7 +173,7 @@ bool MacResManager::open(Common::FSNode path, Common::String filename) {
#endif
// First, let's try to see if the Mac converted name exists
- Common::FSNode fsNode = path.getChild("._" + filename);
+ FSNode fsNode = path.getChild("._" + filename);
if (fsNode.exists() && !fsNode.isDirectory()) {
SeekableReadStream *stream = fsNode.createReadStream();
if (loadFromAppleDouble(*stream)) {
@@ -228,7 +226,7 @@ bool MacResManager::open(Common::FSNode path, Common::String filename) {
return false;
}
-bool MacResManager::loadFromAppleDouble(Common::SeekableReadStream &stream) {
+bool MacResManager::loadFromAppleDouble(SeekableReadStream &stream) {
if (stream.readUint32BE() != 0x00051607) // tag
return false;
@@ -253,7 +251,7 @@ bool MacResManager::loadFromAppleDouble(Common::SeekableReadStream &stream) {
return false;
}
-bool MacResManager::isMacBinary(Common::SeekableReadStream &stream) {
+bool MacResManager::isMacBinary(SeekableReadStream &stream) {
byte infoHeader[MBI_INFOHDR];
int resForkOffset = -1;
@@ -281,7 +279,7 @@ bool MacResManager::isMacBinary(Common::SeekableReadStream &stream) {
return true;
}
-bool MacResManager::loadFromMacBinary(Common::SeekableReadStream &stream) {
+bool MacResManager::loadFromMacBinary(SeekableReadStream &stream) {
byte infoHeader[MBI_INFOHDR];
stream.read(infoHeader, MBI_INFOHDR);
@@ -310,14 +308,14 @@ bool MacResManager::loadFromMacBinary(Common::SeekableReadStream &stream) {
return load(stream);
}
-bool MacResManager::loadFromRawFork(Common::SeekableReadStream &stream) {
+bool MacResManager::loadFromRawFork(SeekableReadStream &stream) {
_mode = kResForkRaw;
_resForkOffset = 0;
_resForkSize = stream.size();
return load(stream);
}
-bool MacResManager::load(Common::SeekableReadStream &stream) {
+bool MacResManager::load(SeekableReadStream &stream) {
if (_mode == kResForkNone)
return false;
@@ -345,7 +343,7 @@ bool MacResManager::load(Common::SeekableReadStream &stream) {
return true;
}
-Common::SeekableReadStream *MacResManager::getDataFork() {
+SeekableReadStream *MacResManager::getDataFork() {
if (!_stream)
return NULL;
@@ -355,7 +353,7 @@ Common::SeekableReadStream *MacResManager::getDataFork() {
return new SeekableSubReadStream(_stream, MBI_INFOHDR, MBI_INFOHDR + dataSize);
}
- Common::File *file = new Common::File();
+ File *file = new File();
if (file->open(_baseFileName))
return file;
delete file;
@@ -398,7 +396,7 @@ MacResTagArray MacResManager::getResTagArray() {
return tagArray;
}
-Common::String MacResManager::getResName(uint32 typeID, uint16 resID) {
+String MacResManager::getResName(uint32 typeID, uint16 resID) const {
int typeNum = -1;
for (int i = 0; i < _resMap.numTypes; i++)
@@ -417,7 +415,7 @@ Common::String MacResManager::getResName(uint32 typeID, uint16 resID) {
return "";
}
-Common::SeekableReadStream *MacResManager::getResource(uint32 typeID, uint16 resID) {
+SeekableReadStream *MacResManager::getResource(uint32 typeID, uint16 resID) {
int typeNum = -1;
int resNum = -1;
@@ -449,7 +447,7 @@ Common::SeekableReadStream *MacResManager::getResource(uint32 typeID, uint16 res
return _stream->readStream(len);
}
-Common::SeekableReadStream *MacResManager::getResource(const Common::String &filename) {
+SeekableReadStream *MacResManager::getResource(const String &filename) {
for (uint32 i = 0; i < _resMap.numTypes; i++) {
for (uint32 j = 0; j < _resTypes[i].items; j++) {
if (_resLists[i][j].nameOffset != -1 && filename.equalsIgnoreCase(_resLists[i][j].name)) {
@@ -468,7 +466,7 @@ Common::SeekableReadStream *MacResManager::getResource(const Common::String &fil
return 0;
}
-Common::SeekableReadStream *MacResManager::getResource(uint32 typeID, const Common::String &filename) {
+SeekableReadStream *MacResManager::getResource(uint32 typeID, const String &filename) {
for (uint32 i = 0; i < _resMap.numTypes; i++) {
if (_resTypes[i].id != typeID)
continue;
@@ -545,7 +543,7 @@ void MacResManager::readMap() {
void MacResManager::convertCrsrCursor(byte *data, int datasize, byte **cursor, int *w, int *h,
int *hotspot_x, int *hotspot_y, int *keycolor, bool colored, byte **palette, int *palSize) {
- Common::MemoryReadStream dis(data, datasize);
+ MemoryReadStream dis(data, datasize);
int i, b;
byte imageByte;
byte *iconData;
diff --git a/common/macresman.h b/common/macresman.h
index d47b0ca329..f88ba9ceb5 100644
--- a/common/macresman.h
+++ b/common/macresman.h
@@ -33,8 +33,8 @@ namespace Common {
class FSNode;
-typedef Common::Array<uint16> MacResIDArray;
-typedef Common::Array<uint32> MacResTagArray;
+typedef Array<uint16> MacResIDArray;
+typedef Array<uint32> MacResTagArray;
/**
* Class for reading Mac Binary files.
@@ -46,14 +46,14 @@ public:
MacResManager();
~MacResManager();
- bool open(Common::String filename);
- bool open(Common::FSNode path, Common::String filename);
+ bool open(String filename);
+ bool open(FSNode path, String filename);
void close();
- bool hasDataFork();
- bool hasResFork();
+ bool hasDataFork() const;
+ bool hasResFork() const;
- static bool isMacBinary(Common::SeekableReadStream &stream);
+ static bool isMacBinary(SeekableReadStream &stream);
/**
* Read resource from the Mac Binary file
@@ -61,7 +61,7 @@ public:
* @param resID Resource ID to fetch
* @return Pointer to a SeekableReadStream with loaded resource
*/
- Common::SeekableReadStream *getResource(uint32 typeID, uint16 resID);
+ SeekableReadStream *getResource(uint32 typeID, uint16 resID);
/**
* Read resource from the Mac Binary file
@@ -69,7 +69,7 @@ public:
* @param filename filename of the resource
* @return Pointer to a SeekableReadStream with loaded resource
*/
- Common::SeekableReadStream *getResource(const Common::String &filename);
+ SeekableReadStream *getResource(const String &filename);
/**
* Read resource from the Mac Binary file
@@ -77,14 +77,14 @@ public:
* @param filename filename of the resource
* @return Pointer to a SeekableReadStream with loaded resource
*/
- Common::SeekableReadStream *getResource(uint32 typeID, const Common::String &filename);
+ SeekableReadStream *getResource(uint32 typeID, const String &filename);
- Common::SeekableReadStream *getDataFork();
- Common::String getResName(uint32 typeID, uint16 resID);
- uint32 getResForkSize();
- bool getResForkMD5(char *md5str, uint32 length);
+ SeekableReadStream *getDataFork();
+ String getResName(uint32 typeID, uint16 resID) const;
+ uint32 getResForkSize() const;
+ String computeResForkMD5AsString(uint32 length = 0) const;
- Common::String getBaseFileName() { return _baseFileName; }
+ String getBaseFileName() const { return _baseFileName; }
/**
* Convert cursor from crsr format to format suitable for feeding to CursorMan
@@ -117,14 +117,14 @@ public:
MacResTagArray getResTagArray();
private:
- Common::SeekableReadStream *_stream;
- Common::String _baseFileName;
+ SeekableReadStream *_stream;
+ String _baseFileName;
- bool load(Common::SeekableReadStream &stream);
+ bool load(SeekableReadStream &stream);
- bool loadFromRawFork(Common::SeekableReadStream &stream);
- bool loadFromMacBinary(Common::SeekableReadStream &stream);
- bool loadFromAppleDouble(Common::SeekableReadStream &stream);
+ bool loadFromRawFork(SeekableReadStream &stream);
+ bool loadFromMacBinary(SeekableReadStream &stream);
+ bool loadFromAppleDouble(SeekableReadStream &stream);
enum {
kResForkNone = 0,
diff --git a/common/md5.cpp b/common/md5.cpp
index df544ca0f0..e4736e85ca 100644
--- a/common/md5.cpp
+++ b/common/md5.cpp
@@ -246,7 +246,7 @@ void md5_finish(md5_context *ctx, uint8 digest[16]) {
}
-bool md5_file(ReadStream &stream, uint8 digest[16], uint32 length) {
+bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length) {
#ifdef DISABLE_MD5
memset(digest, 0, 16);
@@ -267,12 +267,14 @@ bool md5_file(ReadStream &stream, uint8 digest[16], uint32 length) {
while ((i = stream.read(buf, readlen)) > 0) {
md5_update(&ctx, buf, i);
- length -= i;
- if (restricted && length == 0)
- break;
+ if (restricted) {
+ length -= i;
+ if (length == 0)
+ break;
- if (restricted && sizeof(buf) > length)
- readlen = length;
+ if (sizeof(buf) > length)
+ readlen = length;
+ }
}
md5_finish(&ctx, digest);
@@ -280,16 +282,16 @@ bool md5_file(ReadStream &stream, uint8 digest[16], uint32 length) {
return true;
}
-bool md5_file_string(ReadStream &stream, char *md5str, uint32 length) {
+String computeStreamMD5AsString(ReadStream &stream, uint32 length) {
+ String md5;
uint8 digest[16];
- if (!md5_file(stream, digest, length))
- return false;
-
- for (int i = 0; i < 16; i++) {
- snprintf(md5str + i*2, 3, "%02x", (int)digest[i]);
+ if (computeStreamMD5(stream, digest, length)) {
+ for (int i = 0; i < 16; i++) {
+ md5 += String::format("%02x", (int)digest[i]);
+ }
}
- return true;
+ return md5;
}
} // End of namespace Common
diff --git a/common/md5.h b/common/md5.h
index 1fb937ae9b..29f3aeeb4c 100644
--- a/common/md5.h
+++ b/common/md5.h
@@ -26,18 +26,35 @@
#define COMMON_MD5_H
#include "common/scummsys.h"
+#include "common/str.h"
namespace Common {
class ReadStream;
-bool md5_file(ReadStream &stream, uint8 digest[16], uint32 length = 0);
-
-// The following method work similar to the above one, but
-// instead of computing the binary MD5 digest, it produces
-// a human readable lowercase hexstring representing the digest.
-// The md5str parameter must point to a buffer of 32+1 chars.
-bool md5_file_string(ReadStream &stream, char *md5str, uint32 length = 0);
+/**
+ * Compute the MD5 checksum of the content of the given ReadStream.
+ * The 128 bit MD5 checksum is returned directly in the array digest.
+ * If length is set to a positive value, then only the first length
+ * bytes of the stream are used to compute the checksum.
+ * @param[in] stream the stream of whose data the MD5 is computed
+ * @param[out] digest the computed MD5 checksum
+ * @param[in] length the number of bytes for which to compute the checksum; 0 means all
+ * @return true on success, false if an error occurred
+ */
+bool computeStreamMD5(ReadStream &stream, uint8 digest[16], uint32 length = 0);
+
+/**
+ * Compute the MD5 checksum of the content of the given ReadStream.
+ * The 128 bit MD5 checksum is converted to a human readable
+ * lowercase hex string of length 32.
+ * If length is set to a positive value, then only the first length
+ * bytes of the stream are used to compute the checksum.
+ * @param[in] stream the stream of whose data the MD5 is computed
+ * @param[in] length the number of bytes for which to compute the checksum; 0 means all
+ * @return the MD5 as a hex string on success, and an empty string if an error occurred
+ */
+String computeStreamMD5AsString(ReadStream &stream, uint32 length = 0);
} // End of namespace Common
diff --git a/common/memorypool.cpp b/common/memorypool.cpp
index c677c45ff4..c4dbb5fbbd 100644
--- a/common/memorypool.cpp
+++ b/common/memorypool.cpp
@@ -161,7 +161,7 @@ void MemoryPool::freeUnusedPages() {
}
}
-// printf("freed %d pages out of %d\n", (int)freedPagesCount, (int)_pages.size());
+// debug("freed %d pages out of %d", (int)freedPagesCount, (int)_pages.size());
// Remove all now unused pages
size_t newSize = 0;
diff --git a/common/memorypool.h b/common/memorypool.h
index 7188e854f9..e19d982913 100644
--- a/common/memorypool.h
+++ b/common/memorypool.h
@@ -66,7 +66,7 @@ public:
* Constructor for a memory pool with the given chunk size.
* @param chunkSize the chunk size of this memory pool
*/
- MemoryPool(size_t chunkSize);
+ explicit MemoryPool(size_t chunkSize);
~MemoryPool();
/**
diff --git a/common/mutex.h b/common/mutex.h
index ba5c45c30e..3addaa6b18 100644
--- a/common/mutex.h
+++ b/common/mutex.h
@@ -49,8 +49,8 @@ class StackLock {
void lock();
void unlock();
public:
- StackLock(MutexRef mutex, const char *mutexName = NULL);
- StackLock(const Mutex &mutex, const char *mutexName = NULL);
+ explicit StackLock(MutexRef mutex, const char *mutexName = NULL);
+ explicit StackLock(const Mutex &mutex, const char *mutexName = NULL);
~StackLock();
};
diff --git a/common/ptr.h b/common/ptr.h
index 7307038936..4d7fff1fc2 100644
--- a/common/ptr.h
+++ b/common/ptr.h
@@ -243,7 +243,7 @@ public:
operator bool() const { return _pointer != 0; }
~ScopedPtr() {
- delete _pointer;
+ delete _pointer;
}
/**
@@ -277,7 +277,6 @@ private:
PointerType _pointer;
};
-
} // End of namespace Common
#endif
diff --git a/common/scummsys.h b/common/scummsys.h
index 71873ee4e6..d168544b18 100644
--- a/common/scummsys.h
+++ b/common/scummsys.h
@@ -334,13 +334,6 @@
#define SCUMM_BIG_ENDIAN
#define SCUMM_NEED_ALIGNMENT
-#ifdef KEYCODE_LESS
- #undef KEYCODE_LESS
-#endif
-#ifdef KEYCODE_GREATER
- #undef KEYCODE_GREATER
-#endif
-
#elif defined (__DS__)
#define scumm_stricmp stricmp
@@ -444,5 +437,6 @@
typedef uint16 OverlayColor;
#endif
+#include <common/forbidden.h>
#endif
diff --git a/common/str.cpp b/common/str.cpp
index c3c19adfe6..c21e4412db 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -430,7 +430,7 @@ uint String::hash() const {
}
// static
-String String::printf(const char *fmt, ...) {
+String String::format(const char *fmt, ...) {
String output;
assert(output.isStorageIntern());
diff --git a/common/str.h b/common/str.h
index e3dec6cdc2..56feaacf1b 100644
--- a/common/str.h
+++ b/common/str.h
@@ -218,7 +218,7 @@ public:
/**
* Printf-like function. Returns a formatted String.
*/
- static Common::String printf(const char *fmt, ...) GCC_PRINTF(1,2);
+ static Common::String format(const char *fmt, ...) GCC_PRINTF(1,2);
public:
typedef char * iterator;
diff --git a/common/textconsole.cpp b/common/textconsole.cpp
index 0d0b0aead9..246a9a1fe1 100644
--- a/common/textconsole.cpp
+++ b/common/textconsole.cpp
@@ -22,14 +22,13 @@
* $Id$
*/
+// Disable symbol overrides so that we can use system headers.
+// FIXME: Necessary for the PS2 port, should get rid of this eventually.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
#include "common/textconsole.h"
#include "common/system.h"
-#ifdef _WIN32_WCE
-// This is required for the debugger attachment
-extern bool isSmartphone();
-#endif
-
#ifdef __PLAYSTATION2__
// for those replaced fopen/fread/etc functions
#include "backends/platform/ps2/fileio.h"
diff --git a/common/timer.h b/common/timer.h
index 3a48875842..c87c2b3240 100644
--- a/common/timer.h
+++ b/common/timer.h
@@ -26,7 +26,6 @@
#define COMMON_TIMER_H
#include "common/scummsys.h"
-#include "common/system.h"
#include "common/noncopyable.h"
namespace Common {
diff --git a/common/unzip.cpp b/common/unzip.cpp
index e0ddb8f286..3f084ad861 100644
--- a/common/unzip.cpp
+++ b/common/unzip.cpp
@@ -401,7 +401,7 @@ typedef struct {
/* ===========================================================================
Read a byte from a gz_stream; update next_in and avail_in. Return EOF
for end of file.
- IN assertion: the stream s has been sucessfully opened for reading.
+ IN assertion: the stream s has been successfully opened for reading.
*/
diff --git a/common/util.cpp b/common/util.cpp
index 2fffdca8a6..533795ca9e 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -38,20 +38,20 @@ void hexdump(const byte *data, int len, int bytesPerLine, int startOffset) {
byte c;
int offset = startOffset;
while (len >= bytesPerLine) {
- printf("%06x: ", offset);
+ debugN("%06x: ", offset);
for (i = 0; i < bytesPerLine; i++) {
- printf("%02x ", data[i]);
+ debugN("%02x ", data[i]);
if (i % 4 == 3)
- printf(" ");
+ debugN(" ");
}
- printf(" |");
+ debugN(" |");
for (i = 0; i < bytesPerLine; i++) {
c = data[i];
if (c < 32 || c >= 127)
c = '.';
- printf("%c", c);
+ debugN("%c", c);
}
- printf("|\n");
+ debugN("|\n");
data += bytesPerLine;
len -= bytesPerLine;
offset += bytesPerLine;
@@ -60,25 +60,25 @@ void hexdump(const byte *data, int len, int bytesPerLine, int startOffset) {
if (len <= 0)
return;
- printf("%06x: ", offset);
+ debugN("%06x: ", offset);
for (i = 0; i < bytesPerLine; i++) {
if (i < len)
- printf("%02x ", data[i]);
+ debugN("%02x ", data[i]);
else
- printf(" ");
+ debugN(" ");
if (i % 4 == 3)
- printf(" ");
+ debugN(" ");
}
- printf(" |");
+ debugN(" |");
for (i = 0; i < len; i++) {
c = data[i];
if (c < 32 || c >= 127)
c = '.';
- printf("%c", c);
+ debugN("%c", c);
}
for (; i < bytesPerLine; i++)
- printf(" ");
- printf("|\n");
+ debugN(" ");
+ debugN("|\n");
}
diff --git a/common/util.h b/common/util.h
index 52e4295bbb..699653918a 100644
--- a/common/util.h
+++ b/common/util.h
@@ -63,6 +63,20 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
+/**
+ * @def SCUMMVM_CURRENT_FUNCTION
+ * This macro evaluates to the current function's name on compilers supporting this.
+ */
+#if defined(__GNUC__)
+# define SCUMMVM_CURRENT_FUNCTION __PRETTY_FUNCTION__
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
+# define SCUMMVM_CURRENT_FUNCTION __func__
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
+# define SCUMMVM_CURRENT_FUNCTION __FUNCTION__
+#else
+# define SCUMMVM_CURRENT_FUNCTION "<unknown>"
+#endif
+
namespace Common {
/**
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp
index 1c652fa19d..ab56ba3751 100644
--- a/common/xmlparser.cpp
+++ b/common/xmlparser.cpp
@@ -229,6 +229,47 @@ bool XMLParser::parseKeyValue(Common::String keyName) {
return true;
}
+bool XMLParser::parseIntegerKey(const char *key, int count, ...) {
+ bool result;
+ va_list args;
+ va_start(args, count);
+ result = vparseIntegerKey(key, count, args);
+ va_end(args);
+ return result;
+}
+
+bool XMLParser::parseIntegerKey(const Common::String &key, int count, ...) {
+ bool result;
+ va_list args;
+ va_start(args, count);
+ result = vparseIntegerKey(key.c_str(), count, args);
+ va_end(args);
+ return result;
+}
+
+bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) {
+ char *parseEnd;
+ int *num_ptr;
+
+ while (count--) {
+ while (isspace(*key))
+ key++;
+
+ num_ptr = va_arg(args, int*);
+ *num_ptr = strtol(key, &parseEnd, 10);
+
+ key = parseEnd;
+
+ while (isspace(*key))
+ key++;
+
+ if (count && *key++ != ',')
+ return false;
+ }
+
+ return (*key == 0);
+}
+
bool XMLParser::closeKey() {
bool ignore = false;
bool result = true;
@@ -410,5 +451,61 @@ bool XMLParser::parse() {
return true;
}
+bool XMLParser::skipSpaces() {
+ if (!isspace(_char))
+ return false;
+
+ while (_char && isspace(_char))
+ _char = _stream->readByte();
+
+ return true;
+}
+
+bool XMLParser::skipComments() {
+ if (_char == '<') {
+ _char = _stream->readByte();
+
+ if (_char != '!') {
+ _stream->seek(-1, SEEK_CUR);
+ _char = '<';
+ return false;
+ }
+
+ if (_stream->readByte() != '-' || _stream->readByte() != '-')
+ return parserError("Malformed comment syntax.");
+
+ _char = _stream->readByte();
+
+ while (_char) {
+ if (_char == '-') {
+ if (_stream->readByte() == '-') {
+
+ if (_stream->readByte() != '>')
+ return parserError("Malformed comment (double-hyphen inside comment body).");
+
+ _char = _stream->readByte();
+ return true;
+ }
+ }
+
+ _char = _stream->readByte();
+ }
+
+ return parserError("Comment has no closure.");
+ }
+
+ return false;
+}
+
+bool XMLParser::parseToken() {
+ _token.clear();
+
+ while (isValidNameChar(_char)) {
+ _token += _char;
+ _char = _stream->readByte();
+ }
+
+ return isspace(_char) != 0 || _char == '>' || _char == '=' || _char == '/';
}
+} // End of namespace Common
diff --git a/common/xmlparser.h b/common/xmlparser.h
index 5271917927..c8cc349a6c 100644
--- a/common/xmlparser.h
+++ b/common/xmlparser.h
@@ -293,65 +293,22 @@ protected:
/**
* Prints an error message when parsing fails and stops the parser.
- * Parser error always returns "false" so we can pass the return value directly
- * and break down the parsing.
+ * Parser error always returns "false" so we can pass the return value
+ * directly and break down the parsing.
*/
bool parserError(const char *errorString, ...) GCC_PRINTF(2, 3);
/**
- * Skips spaces/whitelines etc. Returns true if any spaces were skipped.
+ * Skips spaces/whitelines etc.
+ * @return true if any spaces were skipped.
*/
- bool skipSpaces() {
- if (!isspace(_char))
- return false;
-
- while (_char && isspace(_char))
- _char = _stream->readByte();
-
- return true;
- }
+ bool skipSpaces();
/**
* Skips comment blocks and comment lines.
- * Returns true if any comments were skipped.
- * Overload this if you want to disable comments on your XML syntax
- * or to change the commenting syntax.
+ * @return true if any comments were skipped.
*/
- virtual bool skipComments() {
- if (_char == '<') {
- _char = _stream->readByte();
-
- if (_char != '!') {
- _stream->seek(-1, SEEK_CUR);
- _char = '<';
- return false;
- }
-
- if (_stream->readByte() != '-' || _stream->readByte() != '-')
- return parserError("Malformed comment syntax.");
-
- _char = _stream->readByte();
-
- while (_char) {
- if (_char == '-') {
- if (_stream->readByte() == '-') {
-
- if (_stream->readByte() != '>')
- return parserError("Malformed comment (double-hyphen inside comment body).");
-
- _char = _stream->readByte();
- return true;
- }
- }
-
- _char = _stream->readByte();
- }
-
- return parserError("Comment has no closure.");
- }
-
- return false;
- }
+ bool skipComments();
/**
* Check if a given character can be part of a KEY or VALUE name.
@@ -364,18 +321,8 @@ protected:
/**
* Parses a the first textual token found.
- * There's no reason to overload this.
*/
- bool parseToken() {
- _token.clear();
-
- while (isValidNameChar(_char)) {
- _token += _char;
- _char = _stream->readByte();
- }
-
- return isspace(_char) != 0 || _char == '>' || _char == '=' || _char == '/';
- }
+ bool parseToken();
/**
* Parses the values inside an integer key.
@@ -395,32 +342,9 @@ protected:
* by reference.
* @returns True if the parsing succeeded.
*/
- bool parseIntegerKey(const char *key, int count, ...) {
- char *parseEnd;
- int *num_ptr;
-
- va_list args;
- va_start(args, count);
-
- while (count--) {
- while (isspace(*key))
- key++;
-
- num_ptr = va_arg(args, int*);
- *num_ptr = strtol(key, &parseEnd, 10);
-
- key = parseEnd;
-
- while (isspace(*key))
- key++;
-
- if (count && *key++ != ',')
- return false;
- }
-
- va_end(args);
- return (*key == 0);
- }
+ bool parseIntegerKey(const char *key, int count, ...);
+ bool parseIntegerKey(const Common::String &keyStr, int count, ...);
+ bool vparseIntegerKey(const char *key, int count, va_list args);
bool parseXMLHeader(ParserNode *node);
@@ -446,6 +370,6 @@ private:
Common::Stack<ParserNode*> _activeKey; /** Node stack of the parsed keys */
};
-}
+} // End of namespace Common
#endif