[Scummvm-cvs-logs] SF.net SVN: scummvm:[39057] scummvm/trunk/engines/sci/scicore

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Mar 1 23:03:37 CET 2009


Revision: 39057
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39057&view=rev
Author:   fingolfin
Date:     2009-03-01 22:03:37 +0000 (Sun, 01 Mar 2009)

Log Message:
-----------
SCI: Unified some of the decompression funcs (they share so much code, would be nice to reduce the code duplication)

Modified Paths:
--------------
    scummvm/trunk/engines/sci/scicore/decompress0.cpp
    scummvm/trunk/engines/sci/scicore/decompress01.cpp
    scummvm/trunk/engines/sci/scicore/decompress1.cpp
    scummvm/trunk/engines/sci/scicore/decompress11.cpp

Modified: scummvm/trunk/engines/sci/scicore/decompress0.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress0.cpp	2009-03-01 21:54:53 UTC (rev 39056)
+++ scummvm/trunk/engines/sci/scicore/decompress0.cpp	2009-03-01 22:03:37 UTC (rev 39057)
@@ -269,7 +269,7 @@
 		return SCI_ERROR_EMPTY_OBJECT;
 	}
 
-	buffer = (uint8*)sci_malloc(compressedLength);
+	buffer = (uint8 *)sci_malloc(compressedLength);
 	result->data = (unsigned char *)sci_malloc(result->size);
 
 	if (stream.read(buffer, compressedLength) != compressedLength) {

Modified: scummvm/trunk/engines/sci/scicore/decompress01.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress01.cpp	2009-03-01 21:54:53 UTC (rev 39056)
+++ scummvm/trunk/engines/sci/scicore/decompress01.cpp	2009-03-01 22:03:37 UTC (rev 39057)
@@ -494,19 +494,20 @@
 	uint16 compressedLength;
 	uint16 compressionMethod;
 	uint8 *buffer;
+	uint8 type;
 
 	result->id = stream.readUint16LE();
 	if (stream.err())
 		return SCI_ERROR_IO_ERROR;
 
 	result->number = result->id & 0x07ff;
-	uint8 type = result->id >> 11;
+	type = result->id >> 11;
 
-	if ((result->number > sci_max_resource_nr[sci_version] || (type > kResourceTypeInvalid)))
+	result->type = (ResourceType)type;
+
+	if ((result->number > sci_max_resource_nr[sci_version]) || (type > kResourceTypeInvalid))
 		return SCI_ERROR_DECOMPRESSION_INSANE;
 
-	result->type = (ResourceType)type;
-
 	compressedLength = stream.readUint16LE();
 	result->size = stream.readUint16LE();
 	compressionMethod = stream.readUint16LE();
@@ -548,7 +549,6 @@
 #endif
 
 	switch (compressionMethod) {
-
 	case 0: // no compression
 		if (result->size != compressedLength) {
 			free(result->data);
@@ -622,6 +622,7 @@
 	}
 
 	free(buffer);
+
 	return 0;
 }
 

Modified: scummvm/trunk/engines/sci/scicore/decompress1.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress1.cpp	2009-03-01 21:54:53 UTC (rev 39056)
+++ scummvm/trunk/engines/sci/scicore/decompress1.cpp	2009-03-01 22:03:37 UTC (rev 39057)
@@ -261,6 +261,7 @@
 	uint16 compressedLength;
 	uint16 compressionMethod;
 	uint8 *buffer;
+	uint16 type;
 
 	if (sci_version == SCI_VERSION_1_EARLY) {
 		result->id = stream.readUint16LE();
@@ -268,28 +269,25 @@
 			return SCI_ERROR_IO_ERROR;
 
 		result->number = result->id & 0x07ff;
-		uint16 type = result->id >> 11;
+		type = result->id >> 11;
 
-		if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_EARLY]) || (type > kResourceTypeInvalid))
-			return SCI_ERROR_DECOMPRESSION_INSANE;
-
 		result->type = (ResourceType)type;
 	} else {
 		result->id = stream.readByte();
 		if (stream.err())
 			return SCI_ERROR_IO_ERROR;
 
-		uint16 type = result->id & 0x7f;
+		type = result->id & 0x7f;
 		result->number = stream.readUint16LE();
 		if (stream.err())
 			return SCI_ERROR_IO_ERROR;
 
-		if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_LATE]) || (type > kResourceTypeInvalid))
-			return SCI_ERROR_DECOMPRESSION_INSANE;
-
 		result->type = (ResourceType)type;
 	}
 
+	if ((result->number > sci_max_resource_nr[sci_version]) || (type > kResourceTypeInvalid))
+		return SCI_ERROR_DECOMPRESSION_INSANE;
+
 	compressedLength = stream.readUint16LE();
 	result->size = stream.readUint16LE();
 	compressionMethod = stream.readUint16LE();

Modified: scummvm/trunk/engines/sci/scicore/decompress11.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress11.cpp	2009-03-01 21:54:53 UTC (rev 39056)
+++ scummvm/trunk/engines/sci/scicore/decompress11.cpp	2009-03-01 22:03:37 UTC (rev 39057)
@@ -32,8 +32,6 @@
 
 namespace Sci {
 
-void decryptinit3();
-int decrypt3(uint8* dest, uint8* src, int length, int complength);
 int decrypt4(uint8* dest, uint8* src, int length, int complength);
 
 int decompress11(Resource *result, Common::ReadStream &stream, int sci_version) {
@@ -48,6 +46,7 @@
 	uint16 type = result->id & 0x7f;
 	if (type > kResourceTypeInvalid)
 		return SCI_ERROR_DECOMPRESSION_INSANE;
+
 	result->type = (ResourceType)type;
 
 	result->number = stream.readUint16LE();
@@ -72,8 +71,8 @@
 		return SCI_ERROR_EMPTY_OBJECT;
 	}
 
-	buffer = (uint8*)sci_malloc(compressedLength);
-	result->data = (unsigned char*)sci_malloc(result->size);
+	buffer = (uint8 *)sci_malloc(compressedLength);
+	result->data = (unsigned char *)sci_malloc(result->size);
 
 	if (stream.read(buffer, compressedLength) != compressedLength) {
 		free(result->data);
@@ -135,7 +134,7 @@
 		        result->number, getResourceTypeSuffix(result->type),
 		        compressionMethod);
 		free(result->data);
-		result->data = NULL; // So that we know that it didn't work
+		result->data = 0; // So that we know that it didn't work
 		result->status = SCI_STATUS_NOMALLOC;
 		free(buffer);
 		return SCI_ERROR_UNKNOWN_COMPRESSION;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list