diff options
author | Yotam Barnoy | 2010-10-31 11:08:43 +0000 |
---|---|---|
committer | Yotam Barnoy | 2010-10-31 11:08:43 +0000 |
commit | 94c8d0a14df429a1b25bd9f5c5d75497fd0ddbd1 (patch) | |
tree | 3df2a4ae7967c56d464729669fc06ce4e93dff36 /common | |
parent | 8df4278ba8cfbf71228e1927f9db635a9a30a57f (diff) | |
parent | dca3c8d8bfc6c4db38cf8e8291818dd472041d4e (diff) | |
download | scummvm-rg350-94c8d0a14df429a1b25bd9f5c5d75497fd0ddbd1.tar.gz scummvm-rg350-94c8d0a14df429a1b25bd9f5c5d75497fd0ddbd1.tar.bz2 scummvm-rg350-94c8d0a14df429a1b25bd9f5c5d75497fd0ddbd1.zip |
Updated with latest from trunk
svn-id: r53976
Diffstat (limited to 'common')
-rw-r--r-- | common/algorithm.h | 8 | ||||
-rw-r--r-- | common/array.h | 6 | ||||
-rw-r--r-- | common/forbidden.h | 147 | ||||
-rw-r--r-- | common/hashmap.h | 5 | ||||
-rw-r--r-- | common/macresman.cpp | 24 | ||||
-rw-r--r-- | common/macresman.h | 11 | ||||
-rw-r--r-- | common/memorypool.h | 2 | ||||
-rw-r--r-- | common/mutex.h | 4 | ||||
-rw-r--r-- | common/rational.cpp | 29 | ||||
-rw-r--r-- | common/rational.h | 5 | ||||
-rw-r--r-- | common/scummsys.h | 7 | ||||
-rw-r--r-- | common/str.cpp | 31 | ||||
-rw-r--r-- | common/stream.cpp | 32 | ||||
-rw-r--r-- | common/stream.h | 6 | ||||
-rw-r--r-- | common/translation.cpp | 31 | ||||
-rw-r--r-- | common/translation.h | 11 | ||||
-rw-r--r-- | common/unzip.cpp | 4 | ||||
-rw-r--r-- | common/util.h | 14 | ||||
-rw-r--r-- | common/xmlparser.cpp | 97 | ||||
-rw-r--r-- | common/xmlparser.h | 100 |
20 files changed, 406 insertions, 168 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/array.h b/common/array.h index 4cc5369f9f..e3aab66dc6 100644 --- a/common/array.h +++ b/common/array.h @@ -150,6 +150,12 @@ public: insert_aux(_storage + idx, &element, &element + 1); } + void insert_at(int idx, const Array<T> &array) { + assert(idx >= 0 && (uint)idx <= _size); + insert_aux(_storage + idx, array.begin(), array.end()); + } + + T remove_at(int idx) { assert(idx >= 0 && (uint)idx < _size); T tmp = _storage[idx]; diff --git a/common/forbidden.h b/common/forbidden.h new file mode 100644 index 0000000000..cc71c36711 --- /dev/null +++ b/common/forbidden.h @@ -0,0 +1,147 @@ +/* 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 + + +// +// 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 + +#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.h b/common/hashmap.h index 0d4d7663f3..45192256a9 100644 --- a/common/hashmap.h +++ b/common/hashmap.h @@ -42,7 +42,8 @@ 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 @@ -138,7 +139,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; diff --git a/common/macresman.cpp b/common/macresman.cpp index eb6a5939b6..641702b5ec 100644 --- a/common/macresman.cpp +++ b/common/macresman.cpp @@ -110,6 +110,7 @@ bool MacResManager::open(Common::String filename) { _baseFileName = filename; return true; } + delete macResForkRawStream; #endif @@ -169,6 +170,7 @@ bool MacResManager::open(Common::FSNode path, Common::String filename) { _baseFileName = filename; return true; } + delete macResForkRawStream; #endif @@ -466,6 +468,28 @@ Common::SeekableReadStream *MacResManager::getResource(const Common::String &fil return 0; } +Common::SeekableReadStream *MacResManager::getResource(uint32 typeID, const Common::String &filename) { + for (uint32 i = 0; i < _resMap.numTypes; i++) { + if (_resTypes[i].id != typeID) + continue; + + for (uint32 j = 0; j < _resTypes[i].items; j++) { + if (_resLists[i][j].nameOffset != -1 && filename.equalsIgnoreCase(_resLists[i][j].name)) { + _stream->seek(_dataOffset + _resLists[i][j].dataOffset); + uint32 len = _stream->readUint32BE(); + + // Ignore resources with 0 length + if (!len) + return 0; + + return _stream->readStream(len); + } + } + } + + return 0; +} + void MacResManager::readMap() { _stream->seek(_mapOffset + 22); diff --git a/common/macresman.h b/common/macresman.h index 2168235670..d47b0ca329 100644 --- a/common/macresman.h +++ b/common/macresman.h @@ -57,7 +57,7 @@ public: /** * Read resource from the Mac Binary file - * @param typeID FourCC with type ID + * @param typeID FourCC of the type * @param resID Resource ID to fetch * @return Pointer to a SeekableReadStream with loaded resource */ @@ -65,11 +65,20 @@ public: /** * Read resource from the Mac Binary file + * @note This will take the first resource that matches this name, regardless of type * @param filename filename of the resource * @return Pointer to a SeekableReadStream with loaded resource */ Common::SeekableReadStream *getResource(const Common::String &filename); + /** + * Read resource from the Mac Binary file + * @param typeID FourCC of the type + * @param filename filename of the resource + * @return Pointer to a SeekableReadStream with loaded resource + */ + Common::SeekableReadStream *getResource(uint32 typeID, const Common::String &filename); + Common::SeekableReadStream *getDataFork(); Common::String getResName(uint32 typeID, uint16 resID); uint32 getResForkSize(); 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/rational.cpp b/common/rational.cpp index 163044f349..f55c2dcfe3 100644 --- a/common/rational.cpp +++ b/common/rational.cpp @@ -22,6 +22,7 @@ * $Id$ */ +#include "common/debug.h" #include "common/rational.h" #include "common/util.h" #include "common/algorithm.h" @@ -257,38 +258,34 @@ frac_t Rational::toFrac() const { return (_num * FRAC_ONE) / _denom; } -Rational::operator int() const { - return toInt(); -} - -Rational::operator double() const { - return toDouble(); -} - const Rational operator+(int left, const Rational &right) { - Rational tmp = right; - tmp += left; + Rational tmp(left); + tmp += right; return tmp; } const Rational operator-(int left, const Rational &right) { - Rational tmp = right; - tmp -= left; + Rational tmp(left); + tmp -= right; return tmp; } const Rational operator*(int left, const Rational &right) { - Rational tmp = right; - tmp *= left; + Rational tmp(left); + tmp *= right; return tmp; } const Rational operator/(int left, const Rational &right) { - Rational tmp = right; - tmp /= left; + Rational tmp(left); + tmp /= right; return tmp; } +void Rational::debugPrint(int debuglevel, const char *caption) const { + debug(debuglevel, "%s %d/%d", caption, _num, _denom); +} + bool operator==(int left, const Rational &right) { return right == left; } diff --git a/common/rational.h b/common/rational.h index 5ceac36209..bee09d8ddb 100644 --- a/common/rational.h +++ b/common/rational.h @@ -76,9 +76,6 @@ public: bool operator>=(int right) const; bool operator<=(int right) const; - operator int() const; - operator double() const; - void invert(); Rational getInverse() const; @@ -86,6 +83,8 @@ public: double toDouble() const; frac_t toFrac() const; + void debugPrint(int debuglevel = 0, const char *caption = "Rational:") const; + private: int _num; int _denom; diff --git a/common/scummsys.h b/common/scummsys.h index df8b8e1901..d168544b18 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -243,7 +243,7 @@ #define SCUMM_NEED_ALIGNMENT #endif - // Very BAD hack following, used to avoid triggering an assert in uClibc dingux library + // 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 @@ -315,6 +315,7 @@ #elif defined(__PSP__) #include <malloc.h> + #include "backends/platform/psp/memory.h" #define scumm_stricmp strcasecmp #define scumm_strnicmp strncasecmp @@ -322,6 +323,9 @@ #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 @@ -433,5 +437,6 @@ typedef uint16 OverlayColor; #endif +#include <common/forbidden.h> #endif diff --git a/common/str.cpp b/common/str.cpp index 2961a0c61b..c3c19adfe6 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -439,12 +439,20 @@ String String::printf(const char *fmt, ...) { int len = vsnprintf(output._str, _builtinCapacity, fmt, va); va_end(va); - if (len == -1) { - // MSVC doesn't return the size the full string would take up. - // Try increasing the size of the string until it fits. + if (len == -1 || len == _builtinCapacity - 1) { + // MSVC and IRIX don't return the size the full string would take up. + // MSVC returns -1, IRIX returns the number of characters actually written, + // which is at the most the size of the buffer minus one, as the string is + // truncated to fit. // We assume MSVC failed to output the correct, null-terminated string // if the return value is either -1 or size. + // For IRIX, because we lack a better mechanism, we assume failure + // if the return value equals size - 1. + // The downside to this is that whenever we try to format a string where the + // size is 1 below the built-in capacity, the size is needlessly increased. + + // Try increasing the size of the string until it fits. int size = _builtinCapacity; do { size *= 2; @@ -455,7 +463,7 @@ String String::printf(const char *fmt, ...) { va_start(va, fmt); len = vsnprintf(output._str, size, fmt, va); va_end(va); - } while (len == -1 || len >= size); + } while (len == -1 || len >= size - 1); output._size = len; } else if (len < (int)_builtinCapacity) { // vsnprintf succeeded @@ -691,9 +699,18 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod switch (*pat) { case '*': - // Record pattern / string position for backtracking - p = ++pat; - q = str; + if (*str) { + // Record pattern / string position for backtracking + p = ++pat; + q = str; + } else { + // If we've reached the end of str, we can't backtrack further + // NB: We can't simply check if pat also ended here, because + // the pattern might end with any number of *s. + ++pat; + p = 0; + q = 0; + } // If pattern ended with * -> match if (!*pat) return true; diff --git a/common/stream.cpp b/common/stream.cpp index 718c806ff3..9f8f6127f1 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -231,21 +231,13 @@ BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize, _realBufSize(bufSize) { assert(parentStream); - allocBuf(bufSize); - assert(_buf); -} - -void BufferedReadStream::allocBuf(uint32 bufSize) { _buf = new byte[bufSize]; + assert(_buf); } BufferedReadStream::~BufferedReadStream() { if (_disposeParentStream) delete _parentStream; - deallocBuf(); -} - -void BufferedReadStream::deallocBuf() { delete[] _buf; } @@ -294,7 +286,7 @@ uint32 BufferedReadStream::read(void *dataPtr, uint32 dataSize) { // Satisfy the request from the buffer memcpy(dataPtr, _buf + _pos, dataSize); _pos += dataSize; - } + } return alreadyRead + dataSize; } @@ -309,7 +301,7 @@ bool BufferedSeekableReadStream::seek(int32 offset, int whence) { // Note: We could try to handle SEEK_END and SEEK_SET, too, but // since they are rarely used, it seems not worth the effort. _eos = false; // seeking always cancels EOS - + if (whence == SEEK_CUR && (int)_pos + offset >= 0 && _pos + offset <= _bufSize) { _pos += offset; @@ -334,24 +326,16 @@ BufferedWriteStream::BufferedWriteStream(WriteStream *parentStream, uint32 bufSi _bufSize(bufSize) { assert(parentStream); - allocBuf(bufSize); + _buf = new byte[bufSize]; assert(_buf); } BufferedWriteStream::~BufferedWriteStream() { assert(flush()); - + if (_disposeParentStream) delete _parentStream; - - deallocBuf(); -} - -void BufferedWriteStream::allocBuf(uint32 bufSize) { - _buf = new byte[bufSize]; -} -void BufferedWriteStream::deallocBuf() { delete[] _buf; } @@ -359,7 +343,7 @@ uint32 BufferedWriteStream::write(const void *dataPtr, uint32 dataSize) { // check if we have enough space for writing to the buffer if (_bufSize - _pos >= dataSize) { memcpy(_buf + _pos, dataPtr, dataSize); - _pos += dataSize; + _pos += dataSize; } else if (_bufSize >= dataSize) { // check if we can flush the buffer and load the data // flush the buffer assert(flushBuffer()); @@ -367,7 +351,7 @@ uint32 BufferedWriteStream::write(const void *dataPtr, uint32 dataSize) { _pos += dataSize; } else { // too big for our buffer // flush the buffer - assert(flushBuffer()); + assert(flushBuffer()); return _parentStream->write(dataPtr, dataSize); } return dataSize; @@ -375,7 +359,7 @@ uint32 BufferedWriteStream::write(const void *dataPtr, uint32 dataSize) { bool BufferedWriteStream::flushBuffer() { uint32 bytesToWrite = _pos; - + if (bytesToWrite) { _pos = 0; if (_parentStream->write(_buf, bytesToWrite) != bytesToWrite) diff --git a/common/stream.h b/common/stream.h index 4d673d1539..c6605cb42d 100644 --- a/common/stream.h +++ b/common/stream.h @@ -497,8 +497,6 @@ protected: bool _eos; // end of stream uint32 _bufSize; uint32 _realBufSize; - virtual void allocBuf(uint32 bufSize); // virtual functions to allocate/deallocate the buffer - virtual void deallocBuf(); public: BufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO); @@ -538,13 +536,11 @@ protected: uint32 _pos; uint32 _bufSize; bool flushBuffer(); // write out the data in the buffer - virtual void allocBuf(uint32 bufSize); // virtual functions to allocate/deallocate the buffer - virtual void deallocBuf(); public: BufferedWriteStream(WriteStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO); virtual ~BufferedWriteStream(); - + virtual uint32 write(const void *dataPtr, uint32 dataSize); virtual bool flush(); }; diff --git a/common/translation.cpp b/common/translation.cpp index 1328ed62d2..a33e1a5243 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -213,6 +213,12 @@ const char *TranslationManager::getCurrentCharset() { return _currentCharset.c_str(); } +const char *TranslationManager::getCurrentLanguage() { + if (_currentLang == -1) + return "C"; + return _langs[_currentLang].c_str(); +} + String TranslationManager::getTranslation(const String &message) { return getTranslation(message.c_str()); } @@ -264,18 +270,18 @@ bool TranslationManager::openTranslationsFile(File& inFile) { // First try to open it directly (i.e. using the SearchMan). if (inFile.open("translations.dat")) return true; - + // Then look in the Themepath if we can find the file. if (ConfMan.hasKey("themepath")) return openTranslationsFile(FSNode(ConfMan.get("themepath")), inFile); - + return false; } bool TranslationManager::openTranslationsFile(const FSNode &node, File& inFile, int depth) { if (!node.exists() || !node.isReadable() || !node.isDirectory()) return false; - + // Check if we can find the file in this directory // Since File::open(FSNode) makes all the needed tests, it is not really // necessary to make them here. But it avoid printing warnings. @@ -284,21 +290,21 @@ bool TranslationManager::openTranslationsFile(const FSNode &node, File& inFile, if (inFile.open(fileNode)) return true; } - + // Check if we exceeded the given recursion depth if (depth - 1 == -1) - return false; - + return false; + // Otherwise look for it in sub-directories FSList fileList; if (!node.getChildren(fileList, FSNode::kListDirectoriesOnly)) return false; - + for (FSList::iterator i = fileList.begin(); i != fileList.end(); ++i) { if (openTranslationsFile(*i, inFile, depth == -1 ? - 1 : depth - 1)) return true; } - + // Not found in this directory or its sub-directories return false; } @@ -318,7 +324,7 @@ void TranslationManager::loadTranslationsInfoDat() { // Get number of translations int nbTranslations = in.readUint16BE(); - + // Skip all the block sizes for (int i = 0; i < nbTranslations + 2; ++i) in.readUint16BE(); @@ -467,12 +473,15 @@ String TranslationManager::getTranslation(const String &message, const String &) const TLangArray TranslationManager::getSupportedLanguageNames() const { return TLangArray(); } - + const char *TranslationManager::getCurrentCharset() { return "ASCII"; } +const char *TranslationManager::getCurrentLanguage() { + return "C"; +} + #endif // USE_TRANSLATION } // End of namespace Common - diff --git a/common/translation.h b/common/translation.h index 57c4cc2ac8..ff0a8a2acf 100644 --- a/common/translation.h +++ b/common/translation.h @@ -116,7 +116,7 @@ public: * it returns the original untranslated message. */ String getTranslation(const String &message); - + /** * Returns the translation into the current language of the parameter * message. In case the message isn't found in the translation catalog, @@ -127,7 +127,7 @@ public: * massage without a context or with a different context. */ const char *getTranslation(const char *message, const char *context); - + /** * Returns the translation into the current language of the parameter * message. In case the message isn't found in the translation catalog, @@ -151,6 +151,11 @@ public: */ const char *getCurrentCharset(); + /** + * Returns currently selected translation language + */ + const char *getCurrentLanguage(); + private: #ifdef USE_TRANSLATION /** @@ -208,6 +213,6 @@ private: #define _s(str) str #define _sc(str, ctxt) str -#define DECLARE_TRANSLATION_ADDITIONAL_CONTEXT(str, ctxt) +#define DECLARE_TRANSLATION_ADDITIONAL_CONTEXT(str, ctxt) #endif diff --git a/common/unzip.cpp b/common/unzip.cpp index 6df2ed4848..3f084ad861 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -373,7 +373,7 @@ typedef struct { unz_file_info_internal cur_file_info_internal; /* private info about it*/ } cached_file_in_zip; -typedef Common::HashMap<Common::String, cached_file_in_zip, Common::IgnoreCase_Hash, +typedef Common::HashMap<Common::String, cached_file_in_zip, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ZipHash; /* unz_s contain internal information about the zipfile @@ -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.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 |