aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMatthew Hoops2011-10-07 14:34:22 -0400
committerMatthew Hoops2011-10-07 14:34:22 -0400
commite1dc4db7aa53d1bbc4cdb03d1163c97d049702f5 (patch)
tree9d57b5fdd6737bc3449851a87e573abe7be984a6 /common
parentdeab5b28753155863062746ef1239535f562fd0b (diff)
parent842b471e45ae8b7c1b4516b9bd5bf39d61112077 (diff)
downloadscummvm-rg350-e1dc4db7aa53d1bbc4cdb03d1163c97d049702f5.tar.gz
scummvm-rg350-e1dc4db7aa53d1bbc4cdb03d1163c97d049702f5.tar.bz2
scummvm-rg350-e1dc4db7aa53d1bbc4cdb03d1163c97d049702f5.zip
Merge remote branch 'upstream/master' into pegasus
Conflicts: video/qt_decoder.cpp
Diffstat (limited to 'common')
-rw-r--r--common/config-file.cpp21
-rw-r--r--common/zlib.cpp29
-rw-r--r--common/zlib.h9
3 files changed, 47 insertions, 12 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp
index 1ebd9b5701..81e0ae6b45 100644
--- a/common/config-file.cpp
+++ b/common/config-file.cpp
@@ -26,16 +26,8 @@
#include "common/system.h"
#include "common/textconsole.h"
-#define MAXLINELEN 256
-
namespace Common {
-/**
- * Check whether the given string is a valid section or key name.
- * For that, it must only consist of letters, numbers, dashes and
- * underscores. In particular, white space and "#", "=", "[", "]"
- * are not valid!
- */
bool ConfigFile::isValidName(const String &name) {
const char *p = name.c_str();
while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.'))
@@ -255,10 +247,15 @@ void ConfigFile::renameSection(const String &oldName, const String &newName) {
assert(isValidName(oldName));
assert(isValidName(newName));
- //Section *os = getSection(oldName);
- Section *ns = getSection(newName);
- if (ns) {
- ns->name = newName;
+ Section *os = getSection(oldName);
+ const Section *ns = getSection(newName);
+ if (os) {
+ // HACK: For now we just print a warning, for more info see the TODO
+ // below.
+ if (ns)
+ warning("ConfigFile::renameSection: Section name \"%s\" already used", newName.c_str());
+ else
+ os->name = newName;
}
// TODO: Check here whether there already is a section with the
// new name. Not sure how to cope with that case, we could:
diff --git a/common/zlib.cpp b/common/zlib.cpp
index 86c618830e..70133fea30 100644
--- a/common/zlib.cpp
+++ b/common/zlib.cpp
@@ -49,6 +49,35 @@ bool uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long
return Z_OK == ::uncompress(dst, dstLen, src, srcLen);
}
+bool inflateZlibHeaderless(byte *dst, uint dstLen, const byte *src, uint srcLen) {
+ if (!dst || !dstLen || !src || !srcLen)
+ return false;
+
+ // Initialize zlib
+ z_stream stream;
+ stream.next_in = const_cast<byte *>(src);
+ stream.avail_in = srcLen;
+ stream.next_out = dst;
+ stream.avail_out = dstLen;
+ stream.zalloc = Z_NULL;
+ stream.zfree = Z_NULL;
+ stream.opaque = Z_NULL;
+
+ // Negative MAX_WBITS tells zlib there's no zlib header
+ int err = inflateInit2(&stream, -MAX_WBITS);
+ if (err != Z_OK)
+ return false;
+
+ err = inflate(&stream, Z_SYNC_FLUSH);
+ if (err != Z_OK && err != Z_STREAM_END) {
+ inflateEnd(&stream);
+ return false;
+ }
+
+ inflateEnd(&stream);
+ return true;
+}
+
/**
* A simple wrapper class which can be used to wrap around an arbitrary
* other SeekableReadStream and will then provide on-the-fly decompression support.
diff --git a/common/zlib.h b/common/zlib.h
index 1925034310..7af7df0da8 100644
--- a/common/zlib.h
+++ b/common/zlib.h
@@ -41,6 +41,15 @@ class WriteStream;
*/
bool uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long srcLen);
+/**
+ * Wrapper around zlib's inflate functions. This function will call the
+ * necessary inflate functions to uncompress data compressed with deflate
+ * but *not* with the standard zlib header.
+ *
+ * @return true on success (Z_OK or Z_STREAM_END), false otherwise
+ */
+bool inflateZlibHeaderless(byte *dst, uint dstLen, const byte *src, uint srcLen);
+
#endif
/**