aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/archive.h2
-rw-r--r--common/config-manager.cpp8
-rw-r--r--common/config-manager.h2
-rw-r--r--common/debug.cpp13
-rw-r--r--common/error.cpp3
-rw-r--r--common/error.h2
-rw-r--r--common/ptr.h2
-rw-r--r--common/quicktime.cpp4
-rw-r--r--common/scummsys.h13
-rw-r--r--common/str.cpp20
-rw-r--r--common/str.h13
-rw-r--r--common/system.cpp19
-rw-r--r--common/system.h2
-rw-r--r--common/textconsole.cpp9
-rw-r--r--common/util.h5
-rw-r--r--common/winexe_ne.cpp2
-rw-r--r--common/winexe_pe.h2
17 files changed, 66 insertions, 55 deletions
diff --git a/common/archive.h b/common/archive.h
index 3c75970d60..8400c56d69 100644
--- a/common/archive.h
+++ b/common/archive.h
@@ -143,7 +143,7 @@ class SearchSet : public Archive {
ArchiveNodeList::iterator find(const String &name);
ArchiveNodeList::const_iterator find(const String &name) const;
- // Add an archive keeping the list sorted by ascending priorities.
+ // Add an archive keeping the list sorted by descending priority.
void insert(const Node& node);
public:
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 03fcb20abf..3941e27cc1 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -491,11 +491,9 @@ int ConfigManager::getInt(const String &key, const String &domName) const {
bool ConfigManager::getBool(const String &key, const String &domName) const {
String value(get(key, domName));
-
- if ((value == "true") || (value == "yes") || (value == "1"))
- return true;
- if ((value == "false") || (value == "no") || (value == "0"))
- return false;
+ bool val;
+ if (Common::parseBool(value, val))
+ return val;
error("ConfigManager::getBool(%s,%s): '%s' is not a valid bool",
key.c_str(), domName.c_str(), value.c_str());
diff --git a/common/config-manager.h b/common/config-manager.h
index 6f3f554459..78a62b9808 100644
--- a/common/config-manager.h
+++ b/common/config-manager.h
@@ -147,7 +147,7 @@ public:
static void defragment(); // move in memory to reduce fragmentation
void copyFrom(ConfigManager &source);
-
+
private:
friend class Singleton<SingletonBaseType>;
ConfigManager();
diff --git a/common/debug.cpp b/common/debug.cpp
index dbbb204deb..0dae344bb2 100644
--- a/common/debug.cpp
+++ b/common/debug.cpp
@@ -107,18 +107,13 @@ bool DebugManager::isDebugChannelEnabled(uint32 channel) {
#ifndef DISABLE_TEXT_CONSOLE
static void debugHelper(const char *s, va_list va, bool caret = true) {
- char buf[STRINGBUFLEN];
+ Common::String buf = Common::String::vformat(s, va);
- vsnprintf(buf, STRINGBUFLEN, s, va);
- buf[STRINGBUFLEN-1] = '\0';
-
- if (caret) {
- buf[STRINGBUFLEN-2] = '\0';
- strcat(buf, "\n");
- }
+ if (caret)
+ buf += '\n';
if (g_system)
- g_system->logMessage(LogMessageType::kDebug, buf);
+ g_system->logMessage(LogMessageType::kDebug, buf.c_str());
// TODO: Think of a good fallback in case we do not have
// any OSystem yet.
}
diff --git a/common/error.cpp b/common/error.cpp
index a6c52a0ce9..78178f8e27 100644
--- a/common/error.cpp
+++ b/common/error.cpp
@@ -67,6 +67,9 @@ static String errorToString(ErrorCode errorCode) {
case kEnginePluginNotSupportSaves:
return _s("Engine plugin does not support save states");
+ case kUserCanceled:
+ return _s("User canceled");
+
case kUnknownError:
default:
return _s("Unknown error");
diff --git a/common/error.h b/common/error.h
index 23c12b67e4..7043862eea 100644
--- a/common/error.h
+++ b/common/error.h
@@ -62,6 +62,8 @@ enum ErrorCode {
kEnginePluginNotFound, ///< Failed to find plugin to handle target
kEnginePluginNotSupportSaves, ///< Failed if plugin does not support listing save states
+ kUserCanceled, ///< User has canceled the launching of the game
+
kUnknownError ///< Catch-all error, used if no other error code matches
};
diff --git a/common/ptr.h b/common/ptr.h
index e0d026f964..fc272d3d41 100644
--- a/common/ptr.h
+++ b/common/ptr.h
@@ -240,7 +240,7 @@ public:
operator bool() const { return _pointer != 0; }
~ScopedPtr() {
- delete _pointer;
+ delete _pointer;
}
/**
diff --git a/common/quicktime.cpp b/common/quicktime.cpp
index 57534b301a..ee49b092a4 100644
--- a/common/quicktime.cpp
+++ b/common/quicktime.cpp
@@ -728,7 +728,7 @@ int QuickTimeParser::readESDS(Atom atom) {
byte tag;
int length;
-
+
readMP4Desc(_fd, tag, length);
_fd->readUint16BE(); // id
if (tag == kMP4ESDescTag)
@@ -736,7 +736,7 @@ int QuickTimeParser::readESDS(Atom atom) {
// Check if we've got the Config MPEG-4 header
readMP4Desc(_fd, tag, length);
- if (tag != kMP4DecConfigDescTag)
+ if (tag != kMP4DecConfigDescTag)
return 0;
track->objectTypeMP4 = _fd->readByte();
diff --git a/common/scummsys.h b/common/scummsys.h
index a425befecf..9d4b6a9677 100644
--- a/common/scummsys.h
+++ b/common/scummsys.h
@@ -302,6 +302,19 @@
#define MAXPATHLEN 256
#endif
+#ifndef scumm_va_copy
+ #if defined(va_copy)
+ #define scumm_va_copy va_copy
+ #elif defined(__va_copy)
+ #define scumm_va_copy __va_copy
+ #elif defined(_MSC_VER)
+ #define scumm_va_copy(dst, src) ((dst) = (src))
+ #else
+ #error scumm_va_copy undefined for this port
+ #endif
+#endif
+
+
//
// Typedef our system types unless they have already been defined by config.h,
diff --git a/common/str.cpp b/common/str.cpp
index 223188bdd6..a2cd4a0193 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -25,8 +25,6 @@
#include "common/str.h"
#include "common/util.h"
-#include <stdarg.h>
-
namespace Common {
MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now
@@ -429,10 +427,22 @@ uint String::hash() const {
// static
String String::format(const char *fmt, ...) {
String output;
- assert(output.isStorageIntern());
va_list va;
va_start(va, fmt);
+ output = String::vformat(fmt, va);
+ va_end(va);
+
+ return output;
+}
+
+// static
+String String::vformat(const char *fmt, va_list args) {
+ String output;
+ assert(output.isStorageIntern());
+
+ va_list va;
+ scumm_va_copy(va, args);
int len = vsnprintf(output._str, _builtinCapacity, fmt, va);
va_end(va);
@@ -457,7 +467,7 @@ String String::format(const char *fmt, ...) {
assert(!output.isStorageIntern());
size = output._extern._capacity;
- va_start(va, fmt);
+ scumm_va_copy(va, args);
len = vsnprintf(output._str, size, fmt, va);
va_end(va);
} while (len == -1 || len >= size - 1);
@@ -468,7 +478,7 @@ String String::format(const char *fmt, ...) {
} else {
// vsnprintf didn't have enough space, so grow buffer
output.ensureCapacity(len, false);
- va_start(va, fmt);
+ scumm_va_copy(va, args);
int len2 = vsnprintf(output._str, len+1, fmt, va);
va_end(va);
assert(len == len2);
diff --git a/common/str.h b/common/str.h
index 7b97dfe945..8e07b6233d 100644
--- a/common/str.h
+++ b/common/str.h
@@ -24,6 +24,8 @@
#include "common/scummsys.h"
+#include <stdarg.h>
+
namespace Common {
/**
@@ -213,10 +215,19 @@ public:
uint hash() const;
/**
- * Printf-like function. Returns a formatted String.
+ * Print formatted data into a String object. Similar to sprintf,
+ * except that it stores the result in (variably sized) String
+ * instead of a fixed size buffer.
*/
static Common::String format(const char *fmt, ...) GCC_PRINTF(1,2);
+ /**
+ * Print formatted data into a String object. Similar to vsprintf,
+ * except that it stores the result in (variably sized) String
+ * instead of a fixed size buffer.
+ */
+ static Common::String vformat(const char *fmt, va_list args);
+
public:
typedef char * iterator;
typedef const char * const_iterator;
diff --git a/common/system.cpp b/common/system.cpp
index 2dab687872..8d5bfd39cd 100644
--- a/common/system.cpp
+++ b/common/system.cpp
@@ -21,11 +21,6 @@
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_exit
-#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
-#define FORBIDDEN_SYMBOL_EXCEPTION_fputs
-#define FORBIDDEN_SYMBOL_EXCEPTION_fflush
-#define FORBIDDEN_SYMBOL_EXCEPTION_stdout
-#define FORBIDDEN_SYMBOL_EXCEPTION_stderr
#include "common/system.h"
#include "common/events.h"
@@ -145,20 +140,6 @@ Common::String OSystem::getDefaultConfigFileName() {
return "scummvm.ini";
}
-void OSystem::logMessage(LogMessageType::Type type, const char *message) {
-#if !defined(__PLAYSTATION2__) && !defined(__DS__)
- FILE *output = 0;
-
- if (type == LogMessageType::kInfo || type == LogMessageType::kDebug)
- output = stdout;
- else
- output = stderr;
-
- fputs(message, output);
- fflush(output);
-#endif
-}
-
Common::String OSystem::getSystemLanguage() const {
return "en_US";
}
diff --git a/common/system.h b/common/system.h
index 24728a918c..15fbe386b1 100644
--- a/common/system.h
+++ b/common/system.h
@@ -1125,7 +1125,7 @@ public:
* @param type the type of the message
* @param message the message itself
*/
- virtual void logMessage(LogMessageType::Type type, const char *message);
+ virtual void logMessage(LogMessageType::Type type, const char *message) = 0;
/**
* Open the log file in a way that allows the user to review it,
diff --git a/common/textconsole.cpp b/common/textconsole.cpp
index f2325ac9ad..ffa42e63a0 100644
--- a/common/textconsole.cpp
+++ b/common/textconsole.cpp
@@ -46,14 +46,14 @@ void setErrorHandler(ErrorHandler handler) {
#ifndef DISABLE_TEXT_CONSOLE
void warning(const char *s, ...) {
- char buf[STRINGBUFLEN];
+ Common::String output;
va_list va;
va_start(va, s);
- vsnprintf(buf, STRINGBUFLEN, s, va);
+ output = Common::String::vformat(s, va);
va_end(va);
- Common::String output = Common::String::format("WARNING: %s!\n", buf);
+ output = "WARNING: " + output + "!\n";
if (g_system)
g_system->logMessage(LogMessageType::kWarning, output.c_str());
@@ -64,6 +64,9 @@ void warning(const char *s, ...) {
#endif
void NORETURN_PRE error(const char *s, ...) {
+ // We don't use String::vformat here, as that require
+ // using the heap, and that might be impossible at this
+ // point, e.g. if the error was an "out-of-memory" error.
char buf_input[STRINGBUFLEN];
char buf_output[STRINGBUFLEN];
va_list va;
diff --git a/common/util.h b/common/util.h
index 5837c8beab..cd890c970f 100644
--- a/common/util.h
+++ b/common/util.h
@@ -208,11 +208,6 @@ enum RenderMode {
kRenderAmiga = 5
};
-enum HerculesDimensions {
- kHercW = 720,
- kHercH = 350
-};
-
struct RenderModeDescription {
const char *code;
const char *description;
diff --git a/common/winexe_ne.cpp b/common/winexe_ne.cpp
index 80266ba87e..8690f6795b 100644
--- a/common/winexe_ne.cpp
+++ b/common/winexe_ne.cpp
@@ -136,7 +136,7 @@ bool NEResources::loadFromCompressedEXE(const String &fileName) {
matchPos &= 0xFFF;
}
}
-
+
}
}
diff --git a/common/winexe_pe.h b/common/winexe_pe.h
index cc1d0c9770..b38f2f78f5 100644
--- a/common/winexe_pe.h
+++ b/common/winexe_pe.h
@@ -107,7 +107,7 @@ private:
uint32 offset;
uint32 size;
};
-
+
typedef HashMap<WinResourceID, Resource, WinResourceID_Hash, WinResourceID_EqualTo> LangMap;
typedef HashMap<WinResourceID, LangMap, WinResourceID_Hash, WinResourceID_EqualTo> NameMap;
typedef HashMap<WinResourceID, NameMap, WinResourceID_Hash, WinResourceID_EqualTo> TypeMap;