aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorDreammaster2013-02-15 08:25:09 -0500
committerDreammaster2013-02-15 08:25:09 -0500
commitbb3285d933419b6bdefadc55a6e320855ff0dd27 (patch)
tree2df613c52f854c33cff660ed1b064e2996ed80bb /common
parentd1a19a1d4c3e20b57250e73141d81e8d9b44a2a1 (diff)
parentadc338cd719179a94ff470b28e9584262d7b47e8 (diff)
downloadscummvm-rg350-bb3285d933419b6bdefadc55a6e320855ff0dd27.tar.gz
scummvm-rg350-bb3285d933419b6bdefadc55a6e320855ff0dd27.tar.bz2
scummvm-rg350-bb3285d933419b6bdefadc55a6e320855ff0dd27.zip
Merge branch 'master' into hopkins
Diffstat (limited to 'common')
-rw-r--r--common/bufferedstream.h2
-rw-r--r--common/c++11-compat.h42
-rw-r--r--common/config-file.cpp2
-rw-r--r--common/config-file.h2
-rw-r--r--common/config-manager.h2
-rw-r--r--common/debug-channels.h2
-rw-r--r--common/debug.cpp2
-rw-r--r--common/file.cpp2
-rw-r--r--common/forbidden.h25
-rw-r--r--common/fs.cpp2
-rw-r--r--common/func.h2
-rw-r--r--common/hash-str.h2
-rw-r--r--common/hashmap.cpp2
-rw-r--r--common/hashmap.h2
-rw-r--r--common/iff_container.cpp49
-rw-r--r--common/iff_container.h41
-rw-r--r--common/language.h2
-rw-r--r--common/macresman.cpp4
-rw-r--r--common/memorypool.h2
-rw-r--r--common/memstream.h2
-rw-r--r--common/mutex.cpp2
-rw-r--r--common/platform.h2
-rw-r--r--common/quicktime.cpp8
-rw-r--r--common/quicktime.h5
-rw-r--r--common/random.cpp2
-rw-r--r--common/random.h2
-rw-r--r--common/rect.h2
-rw-r--r--common/scummsys.h5
-rw-r--r--common/singleton.h2
-rw-r--r--common/str.cpp4
-rw-r--r--common/stream.cpp38
-rw-r--r--common/stream.h2
-rw-r--r--common/taskbar.h2
-rw-r--r--common/textconsole.cpp2
-rw-r--r--common/textconsole.h2
-rw-r--r--common/unzip.cpp2
-rw-r--r--common/unzip.h2
-rw-r--r--common/updates.h2
-rw-r--r--common/util.cpp5
-rw-r--r--common/util.h13
-rw-r--r--common/zlib.cpp12
-rw-r--r--common/zlib.h6
42 files changed, 251 insertions, 62 deletions
diff --git a/common/bufferedstream.h b/common/bufferedstream.h
index 55ea8dc13b..6c859c98fe 100644
--- a/common/bufferedstream.h
+++ b/common/bufferedstream.h
@@ -61,6 +61,6 @@ SeekableReadStream *wrapBufferedSeekableReadStream(SeekableReadStream *parentStr
*/
WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize);
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/c++11-compat.h b/common/c++11-compat.h
new file mode 100644
index 0000000000..50d79bd79e
--- /dev/null
+++ b/common/c++11-compat.h
@@ -0,0 +1,42 @@
+/* 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.
+ *
+ */
+
+#ifndef COMMON_CPP11_COMPAT_H
+#define COMMON_CPP11_COMPAT_H
+
+#if __cplusplus >= 201103L
+#error "c++11-compat.h included when C++11 is available"
+#endif
+
+//
+// Custom nullptr replacement. This is not type safe as the real C++11 nullptr
+// though.
+//
+#define nullptr 0
+
+//
+// Replacement for the override keyword. This allows compilation of code
+// which uses it, but does not feature any semantic.
+//
+#define override
+
+#endif
diff --git a/common/config-file.cpp b/common/config-file.cpp
index 4224d7491d..fe042e9eda 100644
--- a/common/config-file.cpp
+++ b/common/config-file.cpp
@@ -380,4 +380,4 @@ void ConfigFile::Section::removeKey(const String &key) {
}
}
-} // End of namespace Common
+} // End of namespace Common
diff --git a/common/config-file.h b/common/config-file.h
index 7bc5604b4c..8bd731c038 100644
--- a/common/config-file.h
+++ b/common/config-file.h
@@ -134,6 +134,6 @@ private:
*/
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/config-manager.h b/common/config-manager.h
index 02d4ec3438..d43a7bec51 100644
--- a/common/config-manager.h
+++ b/common/config-manager.h
@@ -175,7 +175,7 @@ private:
String _filename;
};
-} // End of namespace Common
+} // End of namespace Common
/** Shortcut for accessing the configuration manager. */
#define ConfMan Common::ConfigManager::instance()
diff --git a/common/debug-channels.h b/common/debug-channels.h
index 54de9d491e..40d1ea667e 100644
--- a/common/debug-channels.h
+++ b/common/debug-channels.h
@@ -124,6 +124,6 @@ private:
/** Shortcut for accessing the debug manager. */
#define DebugMan Common::DebugManager::instance()
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/debug.cpp b/common/debug.cpp
index 9c3a93e5a6..ba5479c34d 100644
--- a/common/debug.cpp
+++ b/common/debug.cpp
@@ -102,7 +102,7 @@ bool DebugManager::isDebugChannelEnabled(uint32 channel) {
return (gDebugChannelsEnabled & channel) != 0;
}
-} // End of namespace Common
+} // End of namespace Common
#ifndef DISABLE_TEXT_CONSOLE
diff --git a/common/file.cpp b/common/file.cpp
index 12d73c9973..7ad6bc2e81 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -202,4 +202,4 @@ bool DumpFile::flush() {
return _handle->flush();
}
-} // End of namespace Common
+} // End of namespace Common
diff --git a/common/forbidden.h b/common/forbidden.h
index eec80bba59..9050114442 100644
--- a/common/forbidden.h
+++ b/common/forbidden.h
@@ -333,11 +333,21 @@
#define isalpha(a) FORBIDDEN_SYMBOL_REPLACEMENT
#endif
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_iscntrl
+ #undef iscntrl
+ #define iscntrl(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_isdigit
#undef isdigit
#define isdigit(a) FORBIDDEN_SYMBOL_REPLACEMENT
#endif
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isgraph
+ #undef isgraph
+ #define isgraph(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_isnumber
#undef isnumber
#define isnumber(a) FORBIDDEN_SYMBOL_REPLACEMENT
@@ -348,6 +358,16 @@
#define islower(a) FORBIDDEN_SYMBOL_REPLACEMENT
#endif
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isprint
+ #undef isprint
+ #define isprint(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_ispunct
+ #undef ispunct
+ #define ispunct(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_isspace
#undef isspace
#define isspace(a) FORBIDDEN_SYMBOL_REPLACEMENT
@@ -358,6 +378,11 @@
#define isupper(a) FORBIDDEN_SYMBOL_REPLACEMENT
#endif
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isxdigit
+ #undef isxdigit
+ #define isxdigit(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
#endif // FORBIDDEN_SYMBOL_EXCEPTION_ctype_h
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_mkdir
diff --git a/common/fs.cpp b/common/fs.cpp
index 0143c936d4..19a01074ea 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -335,4 +335,4 @@ int FSDirectory::listMembers(ArchiveMemberList &list) const {
}
-} // End of namespace Common
+} // End of namespace Common
diff --git a/common/func.h b/common/func.h
index db57d73668..a4a80e5406 100644
--- a/common/func.h
+++ b/common/func.h
@@ -535,6 +535,6 @@ GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long);
#undef GENERATE_TRIVIAL_HASH_FUNCTOR
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/hash-str.h b/common/hash-str.h
index 08f0558bfd..190e6922eb 100644
--- a/common/hash-str.h
+++ b/common/hash-str.h
@@ -79,7 +79,7 @@ typedef HashMap<String, String, IgnoreCase_Hash, IgnoreCase_EqualTo> StringMap;
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/hashmap.cpp b/common/hashmap.cpp
index ff8f9db9ce..e505d1dd25 100644
--- a/common/hashmap.cpp
+++ b/common/hashmap.cpp
@@ -106,4 +106,4 @@ void updateHashCollisionStats(int collisions, int dummyHits, int lookups, int ar
}
#endif
-} // End of namespace Common
+} // End of namespace Common
diff --git a/common/hashmap.h b/common/hashmap.h
index 7cf54997e8..42509d67e5 100644
--- a/common/hashmap.h
+++ b/common/hashmap.h
@@ -632,6 +632,6 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::erase(const Key &key) {
#undef HASHMAP_DUMMY_NODE
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/iff_container.cpp b/common/iff_container.cpp
index 7bcbf86e0f..9c6e5f124a 100644
--- a/common/iff_container.cpp
+++ b/common/iff_container.cpp
@@ -22,6 +22,7 @@
#include "common/iff_container.h"
#include "common/substream.h"
+#include "common/util.h"
namespace Common {
@@ -75,4 +76,50 @@ void IFFParser::parse(IFFCallback &callback) {
} while (!stop);
}
-} // End of namespace Common
+
+PackBitsReadStream::PackBitsReadStream(Common::ReadStream &input) : _input(&input) {
+}
+
+PackBitsReadStream::~PackBitsReadStream() {
+}
+
+bool PackBitsReadStream::eos() const {
+ return _input->eos();
+}
+
+uint32 PackBitsReadStream::read(void *dataPtr, uint32 dataSize) {
+ byte *out = (byte *)dataPtr;
+ uint32 left = dataSize;
+
+ uint32 lenR = 0, lenW = 0;
+ while (left > 0 && !_input->eos()) {
+ lenR = _input->readByte();
+
+ if (lenR == 128) {
+ // no-op
+ lenW = 0;
+ } else if (lenR <= 127) {
+ // literal run
+ lenR++;
+ lenW = MIN(lenR, left);
+ for (uint32 j = 0; j < lenW; j++) {
+ *out++ = _input->readByte();
+ }
+ for (; lenR > lenW; lenR--) {
+ _input->readByte();
+ }
+ } else { // len > 128
+ // expand run
+ lenW = MIN((256 - lenR) + 1, left);
+ byte val = _input->readByte();
+ memset(out, val, lenW);
+ out += lenW;
+ }
+
+ left -= lenW;
+ }
+
+ return dataSize - left;
+}
+
+} // End of namespace Common
diff --git a/common/iff_container.h b/common/iff_container.h
index 104ecf0f36..a730930b2c 100644
--- a/common/iff_container.h
+++ b/common/iff_container.h
@@ -77,22 +77,22 @@ page 376) */
#define ID_copy MKTAG('(','c',')',' ')
/* EA IFF 85 Generic Copyright text chunk */
-/* ILBM chunks */
+/* IFF chunks */
#define ID_BMHD MKTAG('B','M','H','D')
-/* ILBM BitmapHeader */
+/* IFF BitmapHeader */
#define ID_CMAP MKTAG('C','M','A','P')
-/* ILBM 8bit RGB colormap */
+/* IFF 8bit RGB colormap */
#define ID_GRAB MKTAG('G','R','A','B')
-/* ILBM "hotspot" coordiantes */
+/* IFF "hotspot" coordiantes */
#define ID_DEST MKTAG('D','E','S','T')
-/* ILBM destination image info */
+/* IFF destination image info */
#define ID_SPRT MKTAG('S','P','R','T')
-/* ILBM sprite identifier */
+/* IFF sprite identifier */
#define ID_CAMG MKTAG('C','A','M','G')
/* Amiga viewportmodes */
#define ID_BODY MKTAG('B','O','D','Y')
-/* ILBM image data */
+/* IFF image data */
#define ID_CRNG MKTAG('C','R','N','G')
/* color cycling */
#define ID_CCRT MKTAG('C','C','R','T')
@@ -114,7 +114,7 @@ page 376) */
#define ID_PCHG MKTAG('P','C','H','G')
/* Line by line palette control information (Sebastiano Vigna) */
#define ID_PRVW MKTAG('P','R','V','W')
-/* A mini duplicate ILBM used for preview (Gary Bonham) */
+/* A mini duplicate IFF used for preview (Gary Bonham) */
#define ID_XBMI MKTAG('X','B','M','I')
/* eXtended BitMap Information (Soft-Logik) */
#define ID_CTBL MKTAG('C','T','B','L')
@@ -239,6 +239,31 @@ public:
};
+/**
+ * Decode a given PackBits encoded stream.
+ *
+ * PackBits is an RLE compression algorithm introduced by Apple. It is also
+ * used to encode ILBM and PBM subtypes of IFF files, and some flavors of
+ * TIFF.
+ *
+ * As there is no compression across row boundaries in the above formats,
+ * read() will extract a *new* line on each call, discarding any alignment
+ * or padding.
+ */
+class PackBitsReadStream : public Common::ReadStream {
+
+protected:
+ Common::ReadStream *_input;
+
+public:
+ PackBitsReadStream(Common::ReadStream &input);
+ ~PackBitsReadStream();
+
+ virtual bool eos() const;
+
+ uint32 read(void *dataPtr, uint32 dataSize);
+};
+
} // namespace Common
#endif
diff --git a/common/language.h b/common/language.h
index db552fc9c4..03b9ebaf8e 100644
--- a/common/language.h
+++ b/common/language.h
@@ -81,6 +81,6 @@ const String getGameGUIOptionsDescriptionLanguage(Common::Language lang);
// TODO: Document this GUIO related function
bool checkGameGUIOptionLanguage(Common::Language lang, const String &str);
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/macresman.cpp b/common/macresman.cpp
index f2f020c6de..00562f746a 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -360,8 +360,8 @@ bool MacResManager::load(SeekableReadStream &stream) {
_mapLength = stream.readUint32BE();
// do sanity check
- if (_dataOffset >= (uint32)stream.size() || _mapOffset >= (uint32)stream.size() ||
- _dataLength + _mapLength > (uint32)stream.size()) {
+ if (stream.eos() || _dataOffset >= (uint32)stream.size() || _mapOffset >= (uint32)stream.size() ||
+ _dataLength + _mapLength > (uint32)stream.size()) {
_resForkOffset = -1;
_mode = kResForkNone;
return false;
diff --git a/common/memorypool.h b/common/memorypool.h
index 9a4e523d53..1cd725b99d 100644
--- a/common/memorypool.h
+++ b/common/memorypool.h
@@ -141,7 +141,7 @@ public:
}
};
-} // End of namespace Common
+} // End of namespace Common
/**
* A custom placement new operator, using an arbitrary MemoryPool.
diff --git a/common/memstream.h b/common/memstream.h
index 497a178ab9..260fb64d84 100644
--- a/common/memstream.h
+++ b/common/memstream.h
@@ -173,6 +173,6 @@ public:
bool seek(int32 offset, int whence = SEEK_SET);
};
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/mutex.cpp b/common/mutex.cpp
index 4e6316528c..f912e79591 100644
--- a/common/mutex.cpp
+++ b/common/mutex.cpp
@@ -75,4 +75,4 @@ void StackLock::unlock() {
g_system->unlockMutex(_mutex);
}
-} // End of namespace Common
+} // End of namespace Common
diff --git a/common/platform.h b/common/platform.h
index b5ead825fc..72f0991409 100644
--- a/common/platform.h
+++ b/common/platform.h
@@ -77,6 +77,6 @@ extern const char *getPlatformCode(Platform id);
extern const char *getPlatformAbbrev(Platform id);
extern const char *getPlatformDescription(Platform id);
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/quicktime.cpp b/common/quicktime.cpp
index 173d3c6a97..a3efc2b443 100644
--- a/common/quicktime.cpp
+++ b/common/quicktime.cpp
@@ -165,6 +165,8 @@ void QuickTimeParser::initParseTable() {
{ &QuickTimeParser::readWAVE, MKTAG('w', 'a', 'v', 'e') },
{ &QuickTimeParser::readESDS, MKTAG('e', 's', 'd', 's') },
{ &QuickTimeParser::readSMI, MKTAG('S', 'M', 'I', ' ') },
+ { &QuickTimeParser::readDefault, MKTAG('g', 'm', 'h', 'd') },
+ { &QuickTimeParser::readLeaf, MKTAG('g', 'm', 'i', 'n') },
{ 0, 0 }
};
@@ -442,7 +444,7 @@ int QuickTimeParser::readELST(Atom atom) {
uint32 offset = 0;
- for (uint32 i = 0; i < track->editCount; i++){
+ for (uint32 i = 0; i < track->editCount; i++) {
track->editList[i].trackDuration = _fd->readUint32BE();
track->editList[i].mediaTime = _fd->readSint32BE();
track->editList[i].mediaRate = Rational(_fd->readUint32BE(), 0x10000);
@@ -477,6 +479,8 @@ int QuickTimeParser::readHDLR(Atom atom) {
track->codecType = CODEC_TYPE_VIDEO;
else if (type == MKTAG('s', 'o', 'u', 'n'))
track->codecType = CODEC_TYPE_AUDIO;
+ else if (type == MKTAG('m', 'u', 's', 'i'))
+ track->codecType = CODEC_TYPE_MIDI;
_fd->readUint32BE(); // component manufacture
_fd->readUint32BE(); // component flags
@@ -540,7 +544,7 @@ int QuickTimeParser::readSTSD(Atom atom) {
_fd->readUint16BE(); // reserved
_fd->readUint16BE(); // index
- track->sampleDescs[i] = readSampleDesc(track, format);
+ track->sampleDescs[i] = readSampleDesc(track, format, size - 16);
debug(0, "size=%d 4CC= %s codec_type=%d", size, tag2str(format), track->codecType);
diff --git a/common/quicktime.h b/common/quicktime.h
index 641718e13a..caa92578b1 100644
--- a/common/quicktime.h
+++ b/common/quicktime.h
@@ -120,7 +120,8 @@ protected:
enum CodecType {
CODEC_TYPE_MOV_OTHER,
CODEC_TYPE_VIDEO,
- CODEC_TYPE_AUDIO
+ CODEC_TYPE_AUDIO,
+ CODEC_TYPE_MIDI
};
struct Track {
@@ -161,7 +162,7 @@ protected:
byte objectTypeMP4;
};
- virtual SampleDesc *readSampleDesc(Track *track, uint32 format) = 0;
+ virtual SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize) = 0;
uint32 _timeScale;
uint32 _duration;
diff --git a/common/random.cpp b/common/random.cpp
index 55fa3cbd30..fd75534c44 100644
--- a/common/random.cpp
+++ b/common/random.cpp
@@ -59,4 +59,4 @@ uint RandomSource::getRandomNumberRng(uint min, uint max) {
return getRandomNumber(max - min) + min;
}
-} // End of namespace Common
+} // End of namespace Common
diff --git a/common/random.h b/common/random.h
index 90f2ed5cb0..c8aec58946 100644
--- a/common/random.h
+++ b/common/random.h
@@ -74,6 +74,6 @@ public:
uint getRandomNumberRng(uint min, uint max);
};
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/rect.h b/common/rect.h
index 8d1243f7e4..5790cf7c0f 100644
--- a/common/rect.h
+++ b/common/rect.h
@@ -266,6 +266,6 @@ struct Rect {
}
};
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/scummsys.h b/common/scummsys.h
index 2f4efe702f..cd8a949ce7 100644
--- a/common/scummsys.h
+++ b/common/scummsys.h
@@ -144,7 +144,10 @@
#endif
#endif
-
+// Include our C++11 compatability header for pre-C++11 compilers.
+#if __cplusplus < 201103L
+#include "common/c++11-compat.h"
+#endif
// Use config.h, generated by configure
#if defined(HAVE_CONFIG_H)
diff --git a/common/singleton.h b/common/singleton.h
index d7078360f3..6e47f119ba 100644
--- a/common/singleton.h
+++ b/common/singleton.h
@@ -97,6 +97,6 @@ protected:
#define DECLARE_SINGLETON(T) \
template<> T *Singleton<T>::_singleton = 0
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/str.cpp b/common/str.cpp
index 84805082ac..61fdcfaf31 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -764,7 +764,7 @@ String tag2string(uint32 tag) {
str[4] = '\0';
// Replace non-printable chars by dot
for (int i = 0; i < 4; ++i) {
- if (!isprint((unsigned char)str[i]))
+ if (!Common::isPrint(str[i]))
str[i] = '.';
}
return String(str);
@@ -850,7 +850,7 @@ size_t strlcat(char *dst, const char *src, size_t size) {
return dstLength + (src - srcStart);
}
-} // End of namespace Common
+} // End of namespace Common
// Portable implementation of stricmp / strcasecmp / strcmpi.
// TODO: Rename this to Common::strcasecmp
diff --git a/common/stream.cpp b/common/stream.cpp
index 85647bfe3a..f49603c882 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -342,7 +342,7 @@ uint32 BufferedReadStream::read(void *dataPtr, uint32 dataSize) {
return alreadyRead + dataSize;
}
-} // End of nameless namespace
+} // End of anonymous namespace
ReadStream *wrapBufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream) {
@@ -379,12 +379,25 @@ BufferedSeekableReadStream::BufferedSeekableReadStream(SeekableReadStream *paren
bool BufferedSeekableReadStream::seek(int32 offset, int whence) {
// If it is a "local" seek, we may get away with "seeking" around
// in the buffer only.
- // 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;
+ int relOffset = 0;
+ switch (whence) {
+ case SEEK_SET:
+ relOffset = offset - pos();
+ break;
+ case SEEK_CUR:
+ relOffset = offset;
+ break;
+ case SEEK_END:
+ relOffset = (size() + offset) - pos();
+ break;
+ default:
+ break;
+ }
+
+ if ((int)_pos + relOffset >= 0 && _pos + relOffset <= _bufSize) {
+ _pos += relOffset;
// Note: we do not need to reset parent's eos flag here. It is
// sufficient that it is reset when actually seeking in the parent.
@@ -393,14 +406,21 @@ bool BufferedSeekableReadStream::seek(int32 offset, int whence) {
// just seek normally in the parent stream.
if (whence == SEEK_CUR)
offset -= (_bufSize - _pos);
- _pos = _bufSize;
+ // We invalidate the buffer here. This assures that successive seeks
+ // do not have the chance to incorrectly think they seeked back into
+ // the buffer.
+ // Note: This does not take full advantage of the buffer. But it is
+ // a simple way to prevent nasty errors. It would be possible to take
+ // full advantage of the buffer by saving its actual start position.
+ // This seems not worth the effort for this seemingly uncommon use.
+ _pos = _bufSize = 0;
_parentStream->seek(offset, whence);
}
return true;
}
-} // End of nameless namespace
+} // End of anonymous namespace
SeekableReadStream *wrapBufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream) {
if (parentStream)
@@ -482,7 +502,7 @@ public:
};
-} // End of nameless namespace
+} // End of anonymous namespace
WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize) {
if (parentStream)
@@ -490,4 +510,4 @@ WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize)
return 0;
}
-} // End of namespace Common
+} // End of namespace Common
diff --git a/common/stream.h b/common/stream.h
index 26c04e5bf6..33ebc95a86 100644
--- a/common/stream.h
+++ b/common/stream.h
@@ -454,6 +454,6 @@ public:
};
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/taskbar.h b/common/taskbar.h
index 6f28028e74..b4ec673739 100644
--- a/common/taskbar.h
+++ b/common/taskbar.h
@@ -136,7 +136,7 @@ public:
virtual void clearError() {}
};
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/textconsole.cpp b/common/textconsole.cpp
index ffa42e63a0..a721c121d5 100644
--- a/common/textconsole.cpp
+++ b/common/textconsole.cpp
@@ -40,7 +40,7 @@ void setErrorHandler(ErrorHandler handler) {
}
-} // End of namespace Common
+} // End of namespace Common
#ifndef DISABLE_TEXT_CONSOLE
diff --git a/common/textconsole.h b/common/textconsole.h
index 364c49b2e9..12f15e5e4b 100644
--- a/common/textconsole.h
+++ b/common/textconsole.h
@@ -56,7 +56,7 @@ typedef void (*ErrorHandler)(const char *msg);
*/
void setErrorHandler(ErrorHandler handler);
-} // End of namespace Common
+} // End of namespace Common
void NORETURN_PRE error(const char *s, ...) GCC_PRINTF(1, 2) NORETURN_POST;
diff --git a/common/unzip.cpp b/common/unzip.cpp
index ab659343a2..69b9ff67cb 100644
--- a/common/unzip.cpp
+++ b/common/unzip.cpp
@@ -1534,4 +1534,4 @@ Archive *makeZipArchive(SeekableReadStream *stream) {
return new ZipArchive(zipFile);
}
-} // End of namespace Common
+} // End of namespace Common
diff --git a/common/unzip.h b/common/unzip.h
index 06480b0054..2e0dae831a 100644
--- a/common/unzip.h
+++ b/common/unzip.h
@@ -56,6 +56,6 @@ Archive *makeZipArchive(const FSNode &node);
*/
Archive *makeZipArchive(SeekableReadStream *stream);
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/updates.h b/common/updates.h
index 4d58a216fb..0012808a17 100644
--- a/common/updates.h
+++ b/common/updates.h
@@ -95,7 +95,7 @@ public:
virtual UpdateInterval getUpdateCheckInterval() { return kUpdateIntervalNotSupported; }
};
-} // End of namespace Common
+} // End of namespace Common
#endif
diff --git a/common/util.cpp b/common/util.cpp
index 4d9ff11c5c..3d40fffff5 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -26,6 +26,7 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_islower
#define FORBIDDEN_SYMBOL_EXCEPTION_isspace
#define FORBIDDEN_SYMBOL_EXCEPTION_isupper
+#define FORBIDDEN_SYMBOL_EXCEPTION_isprint
#include "common/util.h"
@@ -144,4 +145,8 @@ bool isUpper(int c) {
return isupper((byte)c);
}
+bool isPrint(int c) {
+ ENSURE_ASCII_CHAR(c);
+ return isprint((byte)c);
+}
} // End of namespace Common
diff --git a/common/util.h b/common/util.h
index 78340980d5..4ca1c42929 100644
--- a/common/util.h
+++ b/common/util.h
@@ -165,6 +165,17 @@ bool isSpace(int c);
*/
bool isUpper(int c);
-} // End of namespace Common
+/**
+ * Test whether the given character is printable. This includes the space
+ * character (' ').
+ *
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is printable, false otherwise.
+ */
+bool isPrint(int c);
+} // End of namespace Common
#endif
diff --git a/common/zlib.cpp b/common/zlib.cpp
index fc8f351054..920338e57e 100644
--- a/common/zlib.cpp
+++ b/common/zlib.cpp
@@ -392,17 +392,21 @@ public:
#endif // USE_ZLIB
SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped, uint32 knownSize) {
-#if defined(USE_ZLIB)
if (toBeWrapped) {
uint16 header = toBeWrapped->readUint16BE();
bool isCompressed = (header == 0x1F8B ||
((header & 0x0F00) == 0x0800 &&
header % 31 == 0));
toBeWrapped->seek(-2, SEEK_CUR);
- if (isCompressed)
+ if (isCompressed) {
+#if defined(USE_ZLIB)
return new GZipReadStream(toBeWrapped, knownSize);
- }
+#else
+ delete toBeWrapped;
+ return NULL;
#endif
+ }
+ }
return toBeWrapped;
}
@@ -415,4 +419,4 @@ WriteStream *wrapCompressedWriteStream(WriteStream *toBeWrapped) {
}
-} // End of namespace Common
+} // End of namespace Common
diff --git a/common/zlib.h b/common/zlib.h
index 6a840f5fdc..d940f3f3a1 100644
--- a/common/zlib.h
+++ b/common/zlib.h
@@ -103,7 +103,9 @@ bool inflateZlibInstallShield(byte *dst, uint dstLen, const byte *src, uint srcL
* provides transparent on-the-fly decompression. Assumes the data it
* retrieves from the wrapped stream to be either uncompressed or in gzip
* format. In the former case, the original stream is returned unmodified
- * (and in particular, not wrapped).
+ * (and in particular, not wrapped). In the latter case the stream is
+ * returned wrapped, unless there is no ZLIB support, then NULL is returned
+ * and the old stream is destroyed.
*
* Certain GZip-formats don't supply an easily readable length, if you
* still need the length carried along with the stream, and you know
@@ -129,6 +131,6 @@ SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped, ui
*/
WriteStream *wrapCompressedWriteStream(WriteStream *toBeWrapped);
-} // End of namespace Common
+} // End of namespace Common
#endif