diff options
author | Matthew Hoops | 2011-05-11 00:30:02 -0400 |
---|---|---|
committer | Matthew Hoops | 2011-05-11 00:30:28 -0400 |
commit | a1d41da096c0bcf502a85919cb1cb1ee471719c5 (patch) | |
tree | 8c51419daa486f1d4833757db4715dadab6c3497 /common | |
parent | accb0c2a5d0c9e7b353cda4b74f511a498ed8073 (diff) | |
parent | 33c3e19cea2a08fbf26ecbe940763e8ee1c37d28 (diff) | |
download | scummvm-rg350-a1d41da096c0bcf502a85919cb1cb1ee471719c5.tar.gz scummvm-rg350-a1d41da096c0bcf502a85919cb1cb1ee471719c5.tar.bz2 scummvm-rg350-a1d41da096c0bcf502a85919cb1cb1ee471719c5.zip |
Merge remote branch 'upstream/master' into t7g-ios
Conflicts:
audio/decoders/qdm2.h
common/util.cpp
engines/groovie/music.cpp
engines/groovie/resource.h
video/qt_decoder.cpp
video/qt_decoder.h
Diffstat (limited to 'common')
48 files changed, 523 insertions, 489 deletions
diff --git a/common/EventRecorder.cpp b/common/EventRecorder.cpp index 1dedbb5059..d2ad4bc475 100644 --- a/common/EventRecorder.cpp +++ b/common/EventRecorder.cpp @@ -28,6 +28,7 @@ #include "common/config-manager.h" #include "common/random.h" #include "common/savefile.h" +#include "common/textconsole.h" DECLARE_SINGLETON(Common::EventRecorder); diff --git a/common/archive.cpp b/common/archive.cpp index c65408b56e..c2c9c8e702 100644 --- a/common/archive.cpp +++ b/common/archive.cpp @@ -25,8 +25,8 @@ #include "common/archive.h" #include "common/fs.h" -#include "common/util.h" #include "common/system.h" +#include "common/textconsole.h" namespace Common { diff --git a/common/archive.h b/common/archive.h index c12ca79be0..375136fa15 100644 --- a/common/archive.h +++ b/common/archive.h @@ -27,7 +27,6 @@ #define COMMON_ARCHIVE_H #include "common/str.h" -#include "common/hash-str.h" #include "common/list.h" #include "common/ptr.h" #include "common/singleton.h" diff --git a/common/bufferedstream.h b/common/bufferedstream.h index dc074422bb..bb09e77d1d 100644 --- a/common/bufferedstream.h +++ b/common/bufferedstream.h @@ -27,6 +27,7 @@ #define COMMON_BUFFEREDSTREAM_H #include "common/stream.h" +#include "common/types.h" namespace Common { diff --git a/common/config-file.cpp b/common/config-file.cpp index 878d29301f..cd8f0989fc 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -27,7 +27,7 @@ #include "common/file.h" #include "common/savefile.h" #include "common/system.h" -#include "common/util.h" +#include "common/textconsole.h" #define MAXLINELEN 256 diff --git a/common/config-file.h b/common/config-file.h index 2f7d9cb650..231162fb3c 100644 --- a/common/config-file.h +++ b/common/config-file.h @@ -26,13 +26,15 @@ #ifndef COMMON_CONFIG_FILE_H #define COMMON_CONFIG_FILE_H -#include "common/config-manager.h" +#include "common/hash-str.h" #include "common/list.h" #include "common/str.h" -#include "common/stream.h" namespace Common { +class SeekableReadStream; +class WriteStream; + /** * This class allows reading/writing INI style config files. * It is used by the ConfigManager for storage, but can also diff --git a/common/config-manager.cpp b/common/config-manager.cpp index 77c918dcae..5f5c14f8de 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -24,10 +24,11 @@ */ #include "common/config-manager.h" +#include "common/debug.h" #include "common/file.h" #include "common/fs.h" -#include "common/util.h" #include "common/system.h" +#include "common/textconsole.h" DECLARE_SINGLETON(Common::ConfigManager); diff --git a/common/dcl.cpp b/common/dcl.cpp index ef45bc92ba..efe1de0415 100644 --- a/common/dcl.cpp +++ b/common/dcl.cpp @@ -25,11 +25,9 @@ #include "common/dcl.h" #include "common/debug.h" -#include "common/debug-channels.h" -#include "common/endian.h" #include "common/memstream.h" #include "common/stream.h" -#include "common/util.h" +#include "common/textconsole.h" namespace Common { diff --git a/common/debug.cpp b/common/debug.cpp index c87d195b76..a8711055fd 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -24,8 +24,8 @@ #include "common/debug.h" #include "common/debug-channels.h" -#include "common/util.h" #include "common/system.h" +#include "common/textconsole.h" #include <stdarg.h> // For va_list etc. diff --git a/common/endian.h b/common/endian.h index e6c39d3a4c..c645243654 100644 --- a/common/endian.h +++ b/common/endian.h @@ -149,51 +149,57 @@ */ #define MKTAG(a0,a1,a2,a3) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24))) -// Functions for reading/writing native Integers, -// this transparently handles the need for alignment - -#if !defined(SCUMM_NEED_ALIGNMENT) +// Functions for reading/writing native integers. +// They also transparently handle the need for alignment. + +// Test for GCC >= 4.0. These implementations will automatically use +// CPU-specific instructions for unaligned data when they are available (eg. +// MIPS). See also this email thread on scummvm-devel for details: +// <http://thread.gmane.org/gmane.games.devel.scummvm/8063> +// +// Moreover, we activate this code for GCC >= 3.3 but *only* if unaligned access +// is allowed. +#if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3 && !defined(SCUMM_NEED_ALIGNMENT))) FORCEINLINE uint16 READ_UINT16(const void *ptr) { - return *(const uint16 *)(ptr); + struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__)); + return ((const Unaligned16 *)ptr)->val; } FORCEINLINE uint32 READ_UINT32(const void *ptr) { - return *(const uint32 *)(ptr); + struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__)); + return ((const Unaligned32 *)ptr)->val; } FORCEINLINE void WRITE_UINT16(void *ptr, uint16 value) { - *(uint16 *)(ptr) = value; + struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__)); + ((Unaligned16 *)ptr)->val = value; } FORCEINLINE void WRITE_UINT32(void *ptr, uint32 value) { - *(uint32 *)(ptr) = value; + struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__)); + ((Unaligned32 *)ptr)->val = value; } -// test for GCC >= 4.0. these implementations will automatically use CPU-specific -// instructions for unaligned data when they are available (eg. MIPS) -#elif defined(__GNUC__) && (__GNUC__ >= 4) +#elif !defined(SCUMM_NEED_ALIGNMENT) FORCEINLINE uint16 READ_UINT16(const void *ptr) { - struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__)); - return ((const Unaligned16 *)ptr)->val; + return *(const uint16 *)(ptr); } FORCEINLINE uint32 READ_UINT32(const void *ptr) { - struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__)); - return ((const Unaligned32 *)ptr)->val; + return *(const uint32 *)(ptr); } FORCEINLINE void WRITE_UINT16(void *ptr, uint16 value) { - struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__)); - ((Unaligned16 *)ptr)->val = value; + *(uint16 *)(ptr) = value; } FORCEINLINE void WRITE_UINT32(void *ptr, uint32 value) { - struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__)); - ((Unaligned32 *)ptr)->val = value; + *(uint32 *)(ptr) = value; } + // use software fallback by loading each byte explicitely #else diff --git a/common/error.cpp b/common/error.cpp index 6d1e349287..b07e5ebd74 100644 --- a/common/error.cpp +++ b/common/error.cpp @@ -24,51 +24,68 @@ */ #include "common/error.h" -#include "common/util.h" #include "common/translation.h" namespace Common { /** - * Error Table: Maps error codes to their default descriptions + * Maps an error code to equivalent string description. + * + * @param errorCode error code to be converted + * @return a pointer to string description of the error */ - -struct ErrorMessage { - Error error; - const char *errMsg; -}; - -static const ErrorMessage _errMsgTable[] = { - { kInvalidPathError, _s("Invalid Path") }, - { kNoGameDataFoundError, _s("Game Data not found") }, - { kUnsupportedGameidError, _s("Game Id not supported") }, - { kUnsupportedColorMode, _s("Unsupported Color Mode") }, - - { kReadPermissionDenied, _s("Read permission denied") }, - { kWritePermissionDenied, _s("Write permission denied") }, - - // The following three overlap a bit with kInvalidPathError and each other. Which to keep? - { kPathDoesNotExist, _s("Path not exists") }, - { kPathNotDirectory, _s("Path not a directory") }, - { kPathNotFile, _s("Path not a file") }, - - { kCreatingFileFailed, _s("Cannot create file") }, - { kReadingFailed, _s("Reading failed") }, - { kWritingFailed, _s("Writing data failed") }, - - { kUnknownError, _s("Unknown Error") } -}; - -const char *errorToString(Error error) { - - for (int i = 0; i < ARRAYSIZE(_errMsgTable); i++) { - if (error == _errMsgTable[i].error) { - return _errMsgTable[i].errMsg; - } +static String errorToString(ErrorCode errorCode) { + switch (errorCode) { + case kNoError: + return _s("No error"); + case kNoGameDataFoundError: + return _s("Game data not found"); + case kUnsupportedGameidError: + return _s("Game id not supported"); + case kUnsupportedColorMode: + return _s("Unsupported color mode"); + + case kReadPermissionDenied: + return _s("Read permission denied"); + case kWritePermissionDenied: + return _s("Write permission denied"); + + case kPathDoesNotExist: + return _s("Path does not exist"); + case kPathNotDirectory: + return _s("Path not a directory"); + case kPathNotFile: + return _s("Path not a file"); + + case kCreatingFileFailed: + return _s("Cannot create file"); + case kReadingFailed: + return _s("Reading data failed"); + case kWritingFailed: + return _s("Writing data failed"); + + case kEnginePluginNotFound: + return _s("Could not find suitable engine plugin"); + case kEnginePluginNotSupportSaves: + return _s("Engine plugin does not support save states"); + + case kArgumentNotProcessed: + return _s("Command line argument not processed"); + + case kUnknownError: + default: + return _s("Unknown error"); } +} - return _("Unknown Error"); +Error::Error(ErrorCode code) + : _code(code), _desc(errorToString(code)) { } +Error::Error(ErrorCode code, const String &desc) + : _code(code), _desc(errorToString(code) + " (" + desc + ")") { +} + + } // End of namespace Common diff --git a/common/error.h b/common/error.h index 58343114a2..1ffbba723a 100644 --- a/common/error.h +++ b/common/error.h @@ -26,6 +26,8 @@ #ifndef COMMON_ERROR_H #define COMMON_ERROR_H +#include "common/str.h" + namespace Common { /** @@ -37,15 +39,13 @@ namespace Common { /** * Error codes which may be reported by plugins under various circumstances. * - * @todo Clarify the names; add more codes, resp. verify all existing ones are acutally useful. - * Also, try to avoid overlap. - * @todo Maybe introduce a naming convention? E.g. k-NOUN/ACTION-CONDITION-Error, so - * kPathInvalidError would be correct, but these would not be: kInvalidPath, - * kPathInvalid, kPathIsInvalid, kInvalidPathError + * @note Error names should follow the pattern k-NOUN/ACTION-CONDITION-Error. + * So kPathInvalidError would be correct, but these would not be: + * kInvalidPath, kPathInvalid, kPathIsInvalid, kInvalidPathError. + * @todo Adjust all error codes to comply with these conventions. */ -enum Error { +enum ErrorCode { kNoError = 0, ///< No error occurred - kInvalidPathError, ///< Engine initialization: Invalid game path was passed kNoGameDataFoundError, ///< Engine initialization: No game data was found in the specified location kUnsupportedGameidError, ///< Engine initialization: Gameid not supported by this (Meta)Engine kUnsupportedColorMode, ///< Engine initialization: Engine does not support backend's color mode @@ -54,7 +54,6 @@ enum Error { kReadPermissionDenied, ///< Unable to read data due to missing read permission kWritePermissionDenied, ///< Unable to write data due to missing write permission - // The following three overlap a bit with kInvalidPathError and each other. Which to keep? kPathDoesNotExist, ///< The specified path does not exist kPathNotDirectory, ///< The specified path does not point to a directory kPathNotFile, ///< The specified path does not point to a file @@ -64,21 +63,48 @@ enum Error { kWritingFailed, ///< Failure to write data -- disk full? // The following are used by --list-saves - kPluginNotFound, ///< Failed to find plugin to handle tager - kPluginNotSupportSaves, ///< Failed if plugin does not support saves - kNoSavesError, ///< There are no saves to show + kEnginePluginNotFound, ///< Failed to find plugin to handle target + kEnginePluginNotSupportSaves, ///< Failed if plugin does not support listing save states kArgumentNotProcessed, ///< Used in command line parsing + kUnknownError ///< Catch-all error, used if no other error code matches }; /** - * Maps an error code to equivalent string description. - * - * @param error error code to be converted - * @return a pointer to string description of the error + * An Error instance pairs an error code with string description providing more + * details about the error. For every error code, a default description is + * provided, but it is possible to optionally augment that description with + * extra information when creating a new Error instance. */ -const char *errorToString(Error error); +class Error { +protected: + ErrorCode _code; + String _desc; +public: + /** + * Construct a new Error with the specified error code and the default + * error message. + */ + Error(ErrorCode code = kUnknownError); + + /** + * Construct a new Error with the specified error code and an augmented + * error message. Specifically, the provided extra text is suitably + * appended to the default message. + */ + Error(ErrorCode code, const String &extra); + + /** + * Get the description of this error. + */ + const String &getDesc() const { return _desc; } + + /** + * Get the error code of this error. + */ + ErrorCode getCode() const { return _code; } +}; } // End of namespace Common diff --git a/common/file.cpp b/common/file.cpp index dec0f2a953..485255bbdb 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -27,8 +27,7 @@ #include "common/debug.h" #include "common/file.h" #include "common/fs.h" -#include "common/util.h" -#include "common/system.h" +#include "common/textconsole.h" namespace Common { diff --git a/common/file.h b/common/file.h index d28cd9c308..c3805baed7 100644 --- a/common/file.h +++ b/common/file.h @@ -27,6 +27,7 @@ #define COMMON_FILE_H #include "common/scummsys.h" +#include "common/fs.h" #include "common/noncopyable.h" #include "common/str.h" #include "common/stream.h" @@ -34,7 +35,6 @@ namespace Common { class Archive; -class FSNode; /** * TODO: vital to document this core class properly!!! For both users and implementors diff --git a/common/forbidden.h b/common/forbidden.h index 92e662ccc6..af22b2ee21 100644 --- a/common/forbidden.h +++ b/common/forbidden.h @@ -41,18 +41,22 @@ #ifndef FORBIDDEN_SYMBOL_ALLOW_ALL +// Make sure scummsys.h is always included first +#include "common/scummsys.h" + + /** * 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. + * By including a space and some non-alphanumeric symbols we trigger + * a compiler error. By including the words "forbidden symbol" (which + * the compiler will hopefully print along with its own error message), + * we try to make clear what is causing the error. */ -#define FORBIDDEN_SYMBOL_REPLACEMENT FORBIDDEN SYMBOL! +#define FORBIDDEN_SYMBOL_REPLACEMENT FORBIDDEN SYMBOL !%* -/* #ifndef FORBIDDEN_SYMBOL_EXCEPTION_printf #undef printf #define printf FORBIDDEN_SYMBOL_REPLACEMENT @@ -62,7 +66,16 @@ #undef fprintf #define fprintf FORBIDDEN_SYMBOL_REPLACEMENT #endif -*/ + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_vprintf +#undef vprintf +#define vprintf FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_vfprintf +#undef vfprintf +#define vfprintf FORBIDDEN_SYMBOL_REPLACEMENT +#endif #ifndef FORBIDDEN_SYMBOL_EXCEPTION_FILE #undef FILE @@ -131,29 +144,119 @@ #endif -/* -time_t - -time - -difftime - -mktime - -localtime - -clock - -gmtime +// +// Disable various symbols from time.h +// +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h + + /* + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_t + #undef time_t + #define time_t FORBIDDEN_SYMBOL_REPLACEMENT + #endif + */ + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_asctime + #undef asctime + #define asctime(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_clock + #undef clock + #define clock() FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_ctime + #undef ctime + #define ctime(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_difftime + #undef difftime + #define difftime(a,b) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_getdate + #undef getdate + #define getdate(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_gmtime + #undef gmtime + #define gmtime(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_localtime + #undef localtime + #define localtime(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_mktime + #undef mktime + #define mktime(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_time + #undef time + #define time(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + +#endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h + +// +// Disable various symbols from unistd.h +// +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_unistd_h + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_chdir + #undef chdir + #define chdir(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_getcwd + #undef getcwd + #define getcwd(a,b) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_getwd + #undef getwd + #define getwd(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_unlink + #undef unlink + #define unlink(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + +#endif // FORBIDDEN_SYMBOL_EXCEPTION_unistd_h + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_mkdir +#undef mkdir +#define mkdir(a,b) FORBIDDEN_SYMBOL_REPLACEMENT +#endif -system +/* +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_setlocale +#undef setlocale +#define setlocale(a,b) FORBIDDEN_SYMBOL_REPLACEMENT +#endif +*/ -remove +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_setvbuf +#undef setvbuf +#define setvbuf(a,b,c,d) FORBIDDEN_SYMBOL_REPLACEMENT +#endif -setlocale +/* + * We also would like to disable the following symbols; + * however, these are also frequently used in regular code, + * e.g. for method names, so we don't override them. + * - read + * - remove + * - write + * - ... + */ -setvbuf -*/ #endif diff --git a/common/fs.cpp b/common/fs.cpp index 87067df2cc..d3cdc0697f 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -22,8 +22,8 @@ * $Id$ */ -#include "common/util.h" #include "common/system.h" +#include "common/textconsole.h" #include "backends/fs/abstract-fs.h" #include "backends/fs/fs-factory.h" diff --git a/common/fs.h b/common/fs.h index 6b20a05013..f93c11159e 100644 --- a/common/fs.h +++ b/common/fs.h @@ -27,6 +27,8 @@ #include "common/array.h" #include "common/archive.h" +#include "common/hash-str.h" +#include "common/hashmap.h" #include "common/ptr.h" #include "common/str.h" diff --git a/common/hashmap.h b/common/hashmap.h index 233d7f5b16..907a107163 100644 --- a/common/hashmap.h +++ b/common/hashmap.h @@ -47,8 +47,6 @@ #include "common/func.h" -#include "common/str.h" -#include "common/util.h" #ifdef DEBUG_HASH_COLLISIONS #include "common/debug.h" diff --git a/common/iff_container.h b/common/iff_container.h index 01fc8017a9..43a551a239 100644 --- a/common/iff_container.h +++ b/common/iff_container.h @@ -29,7 +29,7 @@ #include "common/endian.h" #include "common/func.h" #include "common/stream.h" -#include "common/util.h" +#include "common/textconsole.h" namespace Common { diff --git a/common/macresman.cpp b/common/macresman.cpp index e7d4a30789..0ecb430532 100644 --- a/common/macresman.cpp +++ b/common/macresman.cpp @@ -31,7 +31,7 @@ #include "common/macresman.h" #include "common/md5.h" #include "common/substream.h" -#include "common/memstream.h" +#include "common/textconsole.h" #ifdef MACOSX #include "common/config-manager.h" @@ -550,127 +550,4 @@ void MacResManager::readMap() { } } -void MacResManager::convertCrsrCursor(SeekableReadStream *data, byte **cursor, int &w, int &h, int &hotspotX, - int &hotspotY, int &keycolor, bool colored, byte **palette, int &palSize) { - - data->readUint16BE(); // type - data->readUint32BE(); // offset to pixel map - data->readUint32BE(); // offset to pixel data - data->readUint32BE(); // expanded cursor data - data->readUint16BE(); // expanded data depth - data->readUint32BE(); // reserved - - // Grab B/W icon data - *cursor = new byte[16 * 16]; - for (int i = 0; i < 32; i++) { - byte imageByte = data->readByte(); - for (int b = 0; b < 8; b++) - cursor[0][i * 8 + b] = (byte)((imageByte & (0x80 >> b)) > 0 ? 0x0F : 0x00); - } - - // Apply mask data - for (int i = 0; i < 32; i++) { - byte imageByte = data->readByte(); - for (int b = 0; b < 8; b++) - if ((imageByte & (0x80 >> b)) == 0) - cursor[0][i * 8 + b] = 0xff; - } - - hotspotY = data->readUint16BE(); - hotspotX = data->readUint16BE(); - w = h = 16; - keycolor = 0xff; - - // Use b/w cursor on backends which don't support cursor palettes - if (!colored) - return; - - data->readUint32BE(); // reserved - data->readUint32BE(); // cursorID - - // Color version of cursor - data->readUint32BE(); // baseAddr - - // Keep only lowbyte for now - data->readByte(); - int iconRowBytes = data->readByte(); - - if (!iconRowBytes) - return; - - int iconBounds[4]; - iconBounds[0] = data->readUint16BE(); - iconBounds[1] = data->readUint16BE(); - iconBounds[2] = data->readUint16BE(); - iconBounds[3] = data->readUint16BE(); - - data->readUint16BE(); // pmVersion - data->readUint16BE(); // packType - data->readUint32BE(); // packSize - - data->readUint32BE(); // hRes - data->readUint32BE(); // vRes - - data->readUint16BE(); // pixelType - data->readUint16BE(); // pixelSize - data->readUint16BE(); // cmpCount - data->readUint16BE(); // cmpSize - - data->readUint32BE(); // planeByte - data->readUint32BE(); // pmTable - data->readUint32BE(); // reserved - - // Pixel data for cursor - int iconDataSize = iconRowBytes * (iconBounds[3] - iconBounds[1]); - byte *iconData = new byte[iconDataSize]; - data->read(iconData, iconDataSize); - - // Color table - data->readUint32BE(); // ctSeed - data->readUint16BE(); // ctFlag - uint16 ctSize = data->readUint16BE() + 1; - - *palette = new byte[ctSize * 3]; - - // Read just high byte of 16-bit color - for (int c = 0; c < ctSize; c++) { - // We just use indices 0..ctSize, so ignore color ID - data->readUint16BE(); // colorID[c] - - palette[0][c * 3 + 0] = data->readByte(); - data->readByte(); - - palette[0][c * 3 + 1] = data->readByte(); - data->readByte(); - - palette[0][c * 3 + 2] = data->readByte(); - data->readByte(); - } - - palSize = ctSize; - - int pixelsPerByte = (iconBounds[2] - iconBounds[0]) / iconRowBytes; - int bpp = 8 / pixelsPerByte; - - // build a mask to make sure the pixels are properly shifted out - int bitmask = 0; - for (int m = 0; m < bpp; m++) { - bitmask <<= 1; - bitmask |= 1; - } - - // Extract pixels from bytes - for (int j = 0; j < iconDataSize; j++) - for (int b = 0; b < pixelsPerByte; b++) { - int idx = j * pixelsPerByte + (pixelsPerByte - 1 - b); - - if (cursor[0][idx] != 0xff) // if mask is not there - cursor[0][idx] = (byte)((iconData[j] >> (b * bpp)) & bitmask); - } - - delete[] iconData; - - assert(data->size() - data->pos() == 0); -} - } // End of namespace Common diff --git a/common/macresman.h b/common/macresman.h index 2ad0b608a1..f588d8f853 100644 --- a/common/macresman.h +++ b/common/macresman.h @@ -33,15 +33,14 @@ */ #include "common/array.h" -#include "common/file.h" +#include "common/fs.h" +#include "common/str.h" #ifndef COMMON_MACRESMAN_H #define COMMON_MACRESMAN_H namespace Common { -class FSNode; - typedef Array<uint16> MacResIDArray; typedef Array<uint32> MacResTagArray; @@ -153,25 +152,6 @@ public: String getBaseFileName() const { return _baseFileName; } /** - * Convert cursor from crsr format to format suitable for feeding to CursorMan - * @param data Pointer to the cursor datax - * @param cursor Pointer to memory where result cursor will be stored. The memory - * block will be malloc()'ed - * @param w Pointer to int where the cursor width will be stored - * @param h Pointer to int where the cursor height will be stored - * @param hotspotX Storage for cursor hotspot X coordinate - * @param hotspotY Storage for cursor hotspot Y coordinate - * @param keycolor Pointer to int where the transpared color value will be stored - * @param colored If set to true then colored cursor will be returned (if any). - * b/w version will be used otherwise - * @param palette Pointer to memory where the cursor palette will be stored. - * The memory will be malloc()'ed - * @param palSize Pointer to integer where the palette size will be stored. - */ - static void convertCrsrCursor(SeekableReadStream *data, byte **cursor, int &w, int &h, int &hotspotX, - int &hotspotY, int &keycolor, bool colored, byte **palette, int &palSize); - - /** * Return list of resource IDs with specified type ID */ MacResIDArray getResIDArray(uint32 typeID); diff --git a/common/md5.cpp b/common/md5.cpp index e4736e85ca..bea9ca0dc5 100644 --- a/common/md5.cpp +++ b/common/md5.cpp @@ -28,10 +28,10 @@ * this program is licensed under the GPL. */ -#include "common/file.h" -#include "common/fs.h" #include "common/md5.h" #include "common/endian.h" +#include "common/str.h" +#include "common/stream.h" namespace Common { diff --git a/common/md5.h b/common/md5.h index 29f3aeeb4c..e613028a5e 100644 --- a/common/md5.h +++ b/common/md5.h @@ -26,11 +26,11 @@ #define COMMON_MD5_H #include "common/scummsys.h" -#include "common/str.h" namespace Common { class ReadStream; +class String; /** * Compute the MD5 checksum of the content of the given ReadStream. diff --git a/common/memstream.h b/common/memstream.h index 13b8e26e8a..ac42e1bad9 100644 --- a/common/memstream.h +++ b/common/memstream.h @@ -27,6 +27,7 @@ #define COMMON_MEMSTREAM_H #include "common/stream.h" +#include "common/types.h" namespace Common { diff --git a/common/quicktime.cpp b/common/quicktime.cpp index 207a2dd5e3..cf50584cc6 100644 --- a/common/quicktime.cpp +++ b/common/quicktime.cpp @@ -36,6 +36,7 @@ #include "common/macresman.h" #include "common/memstream.h" #include "common/quicktime.h" +#include "common/textconsole.h" #include "common/util.h" #include "common/zlib.h" diff --git a/common/scummsys.h b/common/scummsys.h index 6554c70163..8ba983fd6c 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -110,9 +110,19 @@ #include "config.h" #endif -// make sure we really are compiling for WIN32 -#ifndef WIN32 -#undef _MSC_VER +// +// Define scumm_stricmp and scumm_strnicmp +// +#if defined(_WIN32_WCE) || defined(_MSC_VER) + #define scumm_stricmp stricmp + #define scumm_strnicmp _strnicmp + #define snprintf _snprintf +#elif defined(__MINGW32__) || defined(__GP32__) || defined(__DS__) + #define scumm_stricmp stricmp + #define scumm_strnicmp strnicmp +#else + #define scumm_stricmp strcasecmp + #define scumm_strnicmp strncasecmp #endif @@ -126,20 +136,10 @@ // - Define this on a big endian target // SCUMM_NEED_ALIGNMENT // - Define this if your system has problems reading e.g. an int32 from an odd address -// SCUMMVM_DONT_DEFINE_TYPES -// - Define this if you need to provide your own typedefs, e.g. because your -// system headers conflict with our typenames, or because you have odd -// type requirements. // SMALL_SCREEN_DEVICE // - ... // ... -// We define all types in config.h, so we don't want to typedef those types -// here again! -#ifdef HAVE_CONFIG_H -#define SCUMMVM_DONT_DEFINE_TYPES -#endif - // // By default we try to use pragma push/pop to ensure various structs we use @@ -155,203 +155,75 @@ #define SCUMMVM_USE_PRAGMA_PACK -#if defined(__SYMBIAN32__) +#if defined(HAVE_CONFIG_H) + // All settings should have been set in config.h - #define scumm_stricmp strcasecmp - #define scumm_strnicmp strncasecmp +#elif defined(__SYMBIAN32__) #define SCUMM_LITTLE_ENDIAN #define SCUMM_NEED_ALIGNMENT - #define SMALL_SCREEN_DEVICE - - // Enable Symbians own datatypes - // This is done for two reasons - // a) uint is already defined by Symbians libc component - // b) Symbian is using its "own" datatyping, and the Scummvm port - // should follow this to ensure the best compability possible. - #define SCUMMVM_DONT_DEFINE_TYPES - typedef unsigned char byte; - - typedef unsigned char uint8; - typedef signed char int8; - - typedef unsigned short int uint16; - typedef signed short int int16; - - typedef unsigned long int uint32; - typedef signed long int int32; - #elif defined(_WIN32_WCE) - #define scumm_stricmp stricmp - #define scumm_strnicmp _strnicmp - #define snprintf _snprintf - #define SCUMM_LITTLE_ENDIAN - #ifndef __GNUC__ - #define FORCEINLINE __forceinline - #define NORETURN_PRE __declspec(noreturn) - #endif - #define PLUGIN_EXPORT __declspec(dllexport) - - #if _WIN32_WCE < 300 - #define SMALL_SCREEN_DEVICE - #endif - #elif defined(_MSC_VER) - #define scumm_stricmp stricmp - #define scumm_strnicmp _strnicmp - #define snprintf _snprintf - #define SCUMM_LITTLE_ENDIAN - #define FORCEINLINE __forceinline - #define NORETURN_PRE __declspec(noreturn) - #define PLUGIN_EXPORT __declspec(dllexport) - - #elif defined(__MINGW32__) - #define scumm_stricmp stricmp - #define scumm_strnicmp strnicmp - #define SCUMM_LITTLE_ENDIAN - #define PLUGIN_EXPORT __declspec(dllexport) - -#elif defined(UNIX) - - #define scumm_stricmp strcasecmp - #define scumm_strnicmp strncasecmp +#elif defined(SDL_BACKEND) + /* need this for the SDL_BYTEORDER define */ + #include <SDL_byteorder.h> - #ifndef CONFIG_H - /* need this for the SDL_BYTEORDER define */ - #include <SDL_byteorder.h> - - #if SDL_BYTEORDER == SDL_LIL_ENDIAN - #define SCUMM_LITTLE_ENDIAN - #elif SDL_BYTEORDER == SDL_BIG_ENDIAN - #define SCUMM_BIG_ENDIAN - #else - #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set. - #endif - #endif - - // You need to set this manually if necessary -// #define SCUMM_NEED_ALIGNMENT - - // Very BAD hack following, used to avoid triggering an assert in uClibc dingux library - // "toupper" when pressing keyboard function keys. - #if defined(DINGUX) - #undef toupper - #define toupper(c) (((c & 0xFF) >= 97) && ((c & 0xFF) <= 122) ? ((c & 0xFF) - 32) : (c & 0xFF)) + #if SDL_BYTEORDER == SDL_LIL_ENDIAN + #define SCUMM_LITTLE_ENDIAN + #elif SDL_BYTEORDER == SDL_BIG_ENDIAN + #define SCUMM_BIG_ENDIAN + #else + #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set. #endif #elif defined(__DC__) - #define scumm_stricmp strcasecmp - #define scumm_strnicmp strncasecmp - #define SCUMM_LITTLE_ENDIAN #define SCUMM_NEED_ALIGNMENT #elif defined(__GP32__) - #define scumm_stricmp stricmp - #define scumm_strnicmp strnicmp - #define SCUMM_LITTLE_ENDIAN #define SCUMM_NEED_ALIGNMENT - // Override typenames. uint is already defined by system header files. - #define SCUMMVM_DONT_DEFINE_TYPES - typedef unsigned char byte; - - typedef unsigned char uint8; - typedef signed char int8; - - typedef unsigned short int uint16; - typedef signed short int int16; - - typedef unsigned long int uint32; - typedef signed long int int32; - #elif defined(__PLAYSTATION2__) - #define scumm_stricmp strcasecmp - #define scumm_strnicmp strncasecmp - #define SCUMM_LITTLE_ENDIAN #define SCUMM_NEED_ALIGNMENT #elif defined(__N64__) - #define scumm_stricmp strcasecmp - #define scumm_strnicmp strncasecmp - #define SCUMM_BIG_ENDIAN #define SCUMM_NEED_ALIGNMENT - #define STRINGBUFLEN 256 - - #define SCUMMVM_DONT_DEFINE_TYPES - typedef unsigned char byte; - - typedef unsigned char uint8; - typedef signed char int8; - - typedef unsigned short int uint16; - typedef signed short int int16; - - typedef unsigned int uint32; - typedef signed int int32; - - typedef unsigned long long uint64; - typedef signed long long int64; - #elif defined(__PSP__) - #include <malloc.h> - #include "backends/platform/psp/memory.h" - - #define scumm_stricmp strcasecmp - #define scumm_strnicmp strncasecmp - #define SCUMM_LITTLE_ENDIAN #define SCUMM_NEED_ALIGNMENT - /* to make an efficient, inlined memcpy implementation */ - #define memcpy(dst, src, size) psp_memcpy(dst, src, size) - #elif defined(__amigaos4__) - #define scumm_stricmp strcasecmp - #define scumm_strnicmp strncasecmp - #define SCUMM_BIG_ENDIAN #define SCUMM_NEED_ALIGNMENT -#elif defined (__DS__) - - #define scumm_stricmp stricmp - #define scumm_strnicmp strnicmp +#elif defined(__DS__) #define SCUMM_NEED_ALIGNMENT #define SCUMM_LITTLE_ENDIAN - #define SCUMMVM_DONT_DEFINE_TYPES - - #define STRINGBUFLEN 256 -// #define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__) - #elif defined(__WII__) - #define scumm_stricmp strcasecmp - #define scumm_strnicmp strncasecmp - #define SCUMM_BIG_ENDIAN #define SCUMM_NEED_ALIGNMENT @@ -362,47 +234,96 @@ // -// GCC specific stuff +// Some more system specific settings. +// TODO/FIXME: All of these should be moved to backend specific files (such as portdefs.h) // -#if defined(__GNUC__) - #define NORETURN_POST __attribute__((__noreturn__)) - #define PACKED_STRUCT __attribute__((__packed__)) - #define GCC_PRINTF(x,y) __attribute__((__format__(printf, x, y))) +#if defined(__SYMBIAN32__) - #if !defined(FORCEINLINE) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) - #define FORCEINLINE inline __attribute__((__always_inline__)) + #define SMALL_SCREEN_DEVICE + +#elif defined(_WIN32_WCE) + + #if _WIN32_WCE < 300 + #define SMALL_SCREEN_DEVICE #endif -#elif defined(__INTEL_COMPILER) - #define NORETURN_POST __attribute__((__noreturn__)) - #define PACKED_STRUCT __attribute__((__packed__)) - #define GCC_PRINTF(x,y) __attribute__((__format__(printf, x, y))) -#else - #define PACKED_STRUCT - #define GCC_PRINTF(x,y) + +#elif defined(DINGUX) + + // Very BAD hack following, used to avoid triggering an assert in uClibc dingux library + // "toupper" when pressing keyboard function keys. + #undef toupper + #define toupper(c) (((c & 0xFF) >= 97) && ((c & 0xFF) <= 122) ? ((c & 0xFF) - 32) : (c & 0xFF)) + +#elif defined(__PSP__) + + #include <malloc.h> + #include "backends/platform/psp/memory.h" + + /* to make an efficient, inlined memcpy implementation */ + #define memcpy(dst, src, size) psp_memcpy(dst, src, size) + #endif // // Fallbacks / default values for various special macros // +#ifndef GCC_PRINTF + #if defined(__GNUC__) || defined(__INTEL_COMPILER) + #define GCC_PRINTF(x,y) __attribute__((__format__(__printf__, x, y))) + #else + #define GCC_PRINTF(x,y) + #endif +#endif + +#ifndef PACKED_STRUCT + #if defined(__GNUC__) || defined(__INTEL_COMPILER) + #define PACKED_STRUCT __attribute__((__packed__)) + #else + #define PACKED_STRUCT + #endif +#endif + #ifndef FORCEINLINE -#define FORCEINLINE inline + #if defined(_MSC_VER) + #define FORCEINLINE __forceinline + #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) + #define FORCEINLINE inline __attribute__((__always_inline__)) + #else + #define FORCEINLINE inline + #endif #endif #ifndef PLUGIN_EXPORT -#define PLUGIN_EXPORT + #if defined(_MSC_VER) || defined(_WIN32_WCE) || defined(__MINGW32__) + #define PLUGIN_EXPORT __declspec(dllexport) + #else + #define PLUGIN_EXPORT + #endif #endif #ifndef NORETURN_PRE -#define NORETURN_PRE + #if defined(_MSC_VER) + #define NORETURN_PRE __declspec(noreturn) + #else + #define NORETURN_PRE + #endif #endif #ifndef NORETURN_POST -#define NORETURN_POST + #if defined(__GNUC__) || defined(__INTEL_COMPILER) + #define NORETURN_POST __attribute__((__noreturn__)) + #else + #define NORETURN_POST + #endif #endif #ifndef STRINGBUFLEN -#define STRINGBUFLEN 1024 + #if defined(__N64__) || defined(__DS__) + #define STRINGBUFLEN 256 + #else + #define STRINGBUFLEN 1024 + #endif #endif #ifndef MAXPATHLEN @@ -411,9 +332,60 @@ // -// Typedef our system types unless SCUMMVM_DONT_DEFINE_TYPES is set. +// Typedef our system types // -#ifndef SCUMMVM_DONT_DEFINE_TYPES +#if !defined(HAVE_CONFIG_H) && defined(__SYMBIAN32__) + + // Enable Symbians own datatypes + // This is done for two reasons + // a) uint is already defined by Symbians libc component + // b) Symbian is using its "own" datatyping, and the Scummvm port + // should follow this to ensure the best compability possible. + typedef unsigned char byte; + + typedef unsigned char uint8; + typedef signed char int8; + + typedef unsigned short int uint16; + typedef signed short int int16; + + typedef unsigned long int uint32; + typedef signed long int int32; + +#elif !defined(HAVE_CONFIG_H) && defined(__GP32__) + + // Override typenames. uint is already defined by system header files. + typedef unsigned char byte; + + typedef unsigned char uint8; + typedef signed char int8; + + typedef unsigned short int uint16; + typedef signed short int int16; + + typedef unsigned long int uint32; + typedef signed long int int32; + +#elif !defined(HAVE_CONFIG_H) && defined(__N64__) + + typedef unsigned char byte; + + typedef unsigned char uint8; + typedef signed char int8; + + typedef unsigned short int uint16; + typedef signed short int int16; + + typedef unsigned int uint32; + typedef signed int int32; + +#elif !defined(HAVE_CONFIG_H) && defined(__DS__) + + // Do nothing, the SDK defines all types we need in nds/ndstypes.h, + // which we include in our portsdef.h + +#else + typedef unsigned char byte; typedef unsigned char uint8; typedef signed char int8; diff --git a/common/stream.cpp b/common/stream.cpp index c0783b2352..a785ac5164 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -26,9 +26,7 @@ #include "common/stream.h" #include "common/memstream.h" #include "common/substream.h" -#include "common/bufferedstream.h" #include "common/str.h" -#include "common/util.h" namespace Common { @@ -205,7 +203,6 @@ uint32 SubReadStream::read(void *dataPtr, uint32 dataSize) { } dataSize = _parentStream->read(dataPtr, dataSize); - _eos |= _parentStream->eos(); _pos += dataSize; return dataSize; @@ -245,6 +242,13 @@ bool SeekableSubReadStream::seek(int32 offset, int whence) { return ret; } +uint32 SafeSubReadStream::read(void *dataPtr, uint32 dataSize) { + // Make sure the parent stream is at the right position + seek(0, SEEK_CUR); + + return SeekableSubReadStream::read(dataPtr, dataSize); +} + #pragma mark - diff --git a/common/stream.h b/common/stream.h index 65b4971a72..530b50e431 100644 --- a/common/stream.h +++ b/common/stream.h @@ -26,12 +26,12 @@ #ifndef COMMON_STREAM_H #define COMMON_STREAM_H -#include "common/types.h" #include "common/endian.h" +#include "common/scummsys.h" +#include "common/str.h" namespace Common { -class String; class SeekableReadStream; /** diff --git a/common/substream.h b/common/substream.h index dc49ce9ecf..8b83dbda2e 100644 --- a/common/substream.h +++ b/common/substream.h @@ -27,6 +27,7 @@ #define COMMON_SUBSTREAM_H #include "common/stream.h" +#include "common/types.h" namespace Common { @@ -59,7 +60,7 @@ public: delete _parentStream; } - virtual bool eos() const { return _eos; } + virtual bool eos() const { return _eos | _parentStream->eos(); } virtual bool err() const { return _parentStream->err(); } virtual void clearErr() { _eos = false; _parentStream->clearErr(); } virtual uint32 read(void *dataPtr, uint32 dataSize); @@ -101,6 +102,25 @@ public: } }; +/** + * A seekable substream that removes the exclusivity demand required by the + * normal SeekableSubReadStream, at the cost of seek()ing the parent stream + * before each read(). + * + * More than one SafeSubReadStream to the same parent stream can be used + * at the same time; they won't mess up each other. They will, however, + * reposition the parent stream, so don't depend on its position to be + * the same after a read() or seek() on one of its SafeSubReadStream. + */ +class SafeSubReadStream : public SeekableSubReadStream { +public: + SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) : + SeekableSubReadStream(parentStream, begin, end, disposeParentStream) { + } + + virtual uint32 read(void *dataPtr, uint32 dataSize); +}; + } // End of namespace Common diff --git a/common/system.cpp b/common/system.cpp index 1ec7c14617..4e902bcb14 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -28,6 +28,7 @@ #define FORBIDDEN_SYMBOL_ALLOW_ALL #include "common/system.h" +#include "common/str.h" #ifdef __PLAYSTATION2__ // for those replaced fopen/fread/etc functions diff --git a/common/system.h b/common/system.h index c487e727a8..540ffde5a5 100644 --- a/common/system.h +++ b/common/system.h @@ -28,29 +28,27 @@ #include "common/scummsys.h" #include "common/noncopyable.h" -#include "common/rect.h" #include "common/list.h" // For OSystem::getSupportedFormats() - -#include "graphics/palette.h" // for PaletteManager #include "graphics/pixelformat.h" namespace Audio { - class Mixer; +class Mixer; } namespace Graphics { - struct Surface; +struct Surface; } namespace Common { - struct Event; - class EventManager; - class SaveFileManager; - class SearchSet; - class TimerManager; - class SeekableReadStream; - class WriteStream; - class HardwareKeySet; +class EventManager; +struct Rect; +class SaveFileManager; +class SearchSet; +class String; +class TimerManager; +class SeekableReadStream; +class WriteStream; +class HardwareKeySet; } class AudioCDManager; @@ -363,7 +361,7 @@ public: /** * Determine which graphics mode is currently active. - * @return the active graphics mode + * @return the ID of the active graphics mode */ virtual int getGraphicsMode() const = 0; diff --git a/common/textconsole.cpp b/common/textconsole.cpp index 9c72699914..8d62cd4cb2 100644 --- a/common/textconsole.cpp +++ b/common/textconsole.cpp @@ -24,6 +24,7 @@ #include "common/textconsole.h" #include "common/system.h" +#include "common/str.h" namespace Common { diff --git a/common/textconsole.h b/common/textconsole.h index 963d674c3b..5a535f3206 100644 --- a/common/textconsole.h +++ b/common/textconsole.h @@ -66,8 +66,6 @@ void NORETURN_PRE error(const char *s, ...) GCC_PRINTF(1, 2) NORETURN_POST; #ifdef DISABLE_TEXT_CONSOLE -inline int printf(const char *s, ...) { return 0; } - inline void warning(const char *s, ...) {} #else diff --git a/common/translation.cpp b/common/translation.cpp index 407da2c883..5494849f4c 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -32,11 +32,11 @@ #define TRANSLATIONS_DAT_VER 2 #include "common/translation.h" -#include "common/archive.h" #include "common/config-manager.h" #include "common/file.h" #include "common/fs.h" #include "common/system.h" +#include "common/textconsole.h" #ifdef USE_TRANSLATION diff --git a/common/translation.h b/common/translation.h index 523f2f4de7..f8183b6350 100644 --- a/common/translation.h +++ b/common/translation.h @@ -25,6 +25,9 @@ #ifndef COMMON_TRANSLATION_H #define COMMON_TRANSLATION_H +#include "common/array.h" +#include "common/fs.h" +#include "common/str.h" #include "common/singleton.h" #include "common/str-array.h" @@ -33,7 +36,6 @@ namespace Common { class File; -class FSNode; enum TranslationIDs { kTranslationAutodetectId = 0, diff --git a/common/unarj.cpp b/common/unarj.cpp index 2c4225f393..4bda7ac753 100644 --- a/common/unarj.cpp +++ b/common/unarj.cpp @@ -30,12 +30,12 @@ #include "common/scummsys.h" #include "common/archive.h" #include "common/debug.h" -#include "common/util.h" #include "common/unarj.h" #include "common/file.h" #include "common/hash-str.h" #include "common/memstream.h" #include "common/bufferedstream.h" +#include "common/textconsole.h" namespace Common { diff --git a/common/unarj.h b/common/unarj.h index fa7d388542..fe23ba5694 100644 --- a/common/unarj.h +++ b/common/unarj.h @@ -32,10 +32,11 @@ #ifndef COMMON_UNARJ_H #define COMMON_UNARJ_H +#include "common/str.h" + namespace Common { class Archive; -class String; /** * This factory method creates an Archive instance corresponding to the content diff --git a/common/unzip.cpp b/common/unzip.cpp index cd5d37f4bd..d56893f3cd 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -68,6 +68,8 @@ PkWare has also a specification at : ftp://ftp.pkware.com/probdesc.zip */ +// Disable symbol overrides so that we can use zlib.h +#define FORBIDDEN_SYMBOL_ALLOW_ALL #include "common/scummsys.h" @@ -105,7 +107,6 @@ typedef struct { #include "common/fs.h" #include "common/unzip.h" -#include "common/file.h" #include "common/memstream.h" #include "common/hashmap.h" @@ -1470,11 +1471,13 @@ int ZipArchive::listMembers(Common::ArchiveMemberList &list) { while (err == UNZ_OK) { char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; - unzGetCurrentFileInfo(_zipFile, NULL, - szCurrentFileName, sizeof(szCurrentFileName)-1, - NULL, 0, NULL, 0); - list.push_back(ArchiveMemberList::value_type(new GenericArchiveMember(szCurrentFileName, this))); - matches++; + if (unzGetCurrentFileInfo(_zipFile, NULL, + szCurrentFileName, sizeof(szCurrentFileName)-1, + NULL, 0, NULL, 0) == UNZ_OK) { + list.push_back(ArchiveMemberList::value_type(new GenericArchiveMember(szCurrentFileName, this))); + matches++; + } + err = unzGoToNextFile(_zipFile); } @@ -1493,18 +1496,31 @@ Common::SeekableReadStream *ZipArchive::createReadStreamForMember(const Common:: return 0; unz_file_info fileInfo; - unzOpenCurrentFile(_zipFile); - unzGetCurrentFileInfo(_zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0); + if (unzOpenCurrentFile(_zipFile) != UNZ_OK) + return 0; + + if (unzGetCurrentFileInfo(_zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0) != UNZ_OK) + return 0; + byte *buffer = (byte *)malloc(fileInfo.uncompressed_size); assert(buffer); - unzReadCurrentFile(_zipFile, buffer, fileInfo.uncompressed_size); - unzCloseCurrentFile(_zipFile); + + if (unzReadCurrentFile(_zipFile, buffer, fileInfo.uncompressed_size) != (int)fileInfo.uncompressed_size) { + free(buffer); + return 0; + } + + if (unzCloseCurrentFile(_zipFile) != UNZ_OK) { + free(buffer); + return 0; + } + return new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size, DisposeAfterUse::YES); // FIXME: instead of reading all into a memory stream, we could // instead create a new ZipStream class. But then we have to be // careful to handle the case where the client code opens multiple - // files in the archive and tries to use them indepenendtly. + // files in the archive and tries to use them independently. } Archive *makeZipArchive(const String &name) { diff --git a/common/unzip.h b/common/unzip.h index c460840f12..fe7acdcc54 100644 --- a/common/unzip.h +++ b/common/unzip.h @@ -25,12 +25,13 @@ #ifndef COMMON_UNZIP_H #define COMMON_UNZIP_H +#include "common/str.h" + namespace Common { class Archive; class FSNode; class SeekableReadStream; -class String; /** * This factory method creates an Archive instance corresponding to the content diff --git a/common/util.cpp b/common/util.cpp index 06954ac441..22cf33b130 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -23,9 +23,9 @@ */ #include "common/util.h" -#include "common/system.h" #include "common/translation.h" #include "common/config-manager.h" +#include "common/debug.h" namespace Common { @@ -213,7 +213,7 @@ const PlatformDescription g_platforms[] = { { "segacd", "segacd", "sega", "SegaCD", kPlatformSegaCD }, { "windows", "win", "win", "Windows", kPlatformWindows }, { "playstation", "psx", "psx", "Sony PlayStation", kPlatformPSX }, - { "cdi", "cdi", "cdi", "Phillips CD-i", kPlatformCDi }, + { "cdi", "cdi", "cdi", "Philips CD-i", kPlatformCDi }, { "ios", "ios", "ios", "Apple iOS", kPlatformIOS }, { 0, 0, 0, "Default", kPlatformUnknown } diff --git a/common/util.h b/common/util.h index e0bded2f54..3af9b49086 100644 --- a/common/util.h +++ b/common/util.h @@ -26,7 +26,6 @@ #define COMMON_UTIL_H #include "common/scummsys.h" -#include "common/textconsole.h" #include "common/str.h" diff --git a/common/winexe.h b/common/winexe.h index af0d70c555..ce2f19cb81 100644 --- a/common/winexe.h +++ b/common/winexe.h @@ -27,11 +27,10 @@ #define COMMON_WINEXE_H #include "common/hash-str.h" +#include "common/str.h" namespace Common { -class String; - class WinResourceID { public: WinResourceID() { _idType = kIDTypeNull; } diff --git a/common/winexe_ne.h b/common/winexe_ne.h index c1d04080ba..2988132040 100644 --- a/common/winexe_ne.h +++ b/common/winexe_ne.h @@ -26,15 +26,14 @@ #ifndef COMMON_WINEXE_NE_H #define COMMON_WINEXE_NE_H -#include "common/array.h" #include "common/list.h" +#include "common/str.h" #include "common/winexe.h" namespace Common { -class MemoryReadStream; +template<class T> class Array; class SeekableReadStream; -class String; /** The default Windows resources. */ enum NEResourceType { diff --git a/common/winexe_pe.cpp b/common/winexe_pe.cpp index 17db004bfc..6bb831b9c6 100644 --- a/common/winexe_pe.cpp +++ b/common/winexe_pe.cpp @@ -23,9 +23,10 @@ * */ +#include "common/array.h" #include "common/debug.h" +#include "common/endian.h" #include "common/file.h" -#include "common/memstream.h" #include "common/str.h" #include "common/stream.h" #include "common/winexe_pe.h" @@ -123,7 +124,7 @@ void PEResources::parseResourceLevel(Section §ion, uint32 offset, int level) uint16 namedEntryCount = _exe->readUint16LE(); uint16 intEntryCount = _exe->readUint16LE(); - for (uint32 i = 0; i < namedEntryCount + intEntryCount; i++) { + for (uint32 i = 0; i < (uint32)(namedEntryCount + intEntryCount); i++) { uint32 value = _exe->readUint32LE(); WinResourceID id; diff --git a/common/winexe_pe.h b/common/winexe_pe.h index 5298e993ad..60c4adb916 100644 --- a/common/winexe_pe.h +++ b/common/winexe_pe.h @@ -26,14 +26,15 @@ #ifndef COMMON_WINEXE_PE_H #define COMMON_WINEXE_PE_H -#include "common/array.h" +#include "common/hash-str.h" #include "common/hashmap.h" +#include "common/str.h" #include "common/winexe.h" namespace Common { +template<class T> class Array; class SeekableReadStream; -class String; /** The default Windows PE resources. */ enum PEResourceType { diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index b53a9a33c2..e2e1dbdfc7 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -23,8 +23,14 @@ * */ +// FIXME: Avoid using fprintf +#define FORBIDDEN_SYMBOL_EXCEPTION_fprintf + +// FIXME: Avoid using vfprintf +#define FORBIDDEN_SYMBOL_EXCEPTION_vfprintf + + #include "common/xmlparser.h" -#include "common/util.h" #include "common/archive.h" #include "common/fs.h" #include "common/memstream.h" diff --git a/common/xmlparser.h b/common/xmlparser.h index ec8f371681..c456fd0826 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -29,6 +29,7 @@ #include "common/scummsys.h" #include "common/types.h" +#include "common/fs.h" #include "common/list.h" #include "common/hashmap.h" #include "common/hash-str.h" @@ -37,7 +38,6 @@ namespace Common { -class FSNode; class SeekableReadStream; #define MAX_XML_DEPTH 8 diff --git a/common/zlib.cpp b/common/zlib.cpp index 98ecc10c1d..96e9f8cb15 100644 --- a/common/zlib.cpp +++ b/common/zlib.cpp @@ -23,6 +23,9 @@ * */ +// Disable symbol overrides so that we can use zlib.h +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "common/zlib.h" #include "common/util.h" #include "common/stream.h" |