[Scummvm-cvs-logs] SF.net SVN: scummvm:[47365] tools/trunk/engines/mohawk

tdhs at users.sourceforge.net tdhs at users.sourceforge.net
Tue Jan 19 00:46:30 CET 2010


Revision: 47365
          http://scummvm.svn.sourceforge.net/scummvm/?rev=47365&view=rev
Author:   tdhs
Date:     2010-01-18 23:46:28 +0000 (Mon, 18 Jan 2010)

Log Message:
-----------
Cleanup and improvements to extract_mohawk tool :
Support for command line options parsing in clean and expandable manner.
Allow choice of raw binary resource dump or conversion.
More general output file naming convention i.e. File Table Id, Type Tag, Resource Id and (optional) name seperated by underscores with a file type suffix (.bin for raw dump).

Modified Paths:
--------------
    tools/trunk/engines/mohawk/extract_mohawk.cpp
    tools/trunk/engines/mohawk/mohawk_file.cpp
    tools/trunk/engines/mohawk/mohawk_file.h

Modified: tools/trunk/engines/mohawk/extract_mohawk.cpp
===================================================================
--- tools/trunk/engines/mohawk/extract_mohawk.cpp	2010-01-18 23:07:56 UTC (rev 47364)
+++ tools/trunk/engines/mohawk/extract_mohawk.cpp	2010-01-18 23:46:28 UTC (rev 47365)
@@ -29,18 +29,39 @@
 // Have a maximum buffer size
 #define MAX_BUF_SIZE 16384
 
-void printUsage(const char *appName) {
-	printf("Usage: %s <mohawk archive> [tag id]\n", appName);
+static byte *outputBuffer = NULL;
+
+void dumpRawResource(MohawkOutputStream output) {
+	assert(outputBuffer);
+
+	// Change the extension to bin
+	output.name += ".bin";
+
+	printf ("Extracting \'%s\'...\n", output.name.c_str());
+
+	FILE *outputFile = fopen(output.name.c_str(), "wb");
+	if (!outputFile) {
+		printf ("Could not open file for output!\n");
+		return;
+	}
+
+	while (output.stream->pos() < output.stream->size()) {
+		uint32 size = output.stream->read(outputBuffer, MAX_BUF_SIZE);
+		fwrite(outputBuffer, 1, size, outputFile);
+	}
+
+	fflush(outputFile);
+	fclose(outputFile);
 }
 
-static byte *outputBuffer = NULL;
-
 void convertSoundResource(MohawkOutputStream output) {
-	printf ("Converting sounds not yet supported.\n");
+	printf ("Converting sounds not yet supported. Dumping instead...\n");
+	dumpRawResource(output);
 }
 
 void convertMovieResource(MohawkOutputStream output) {
 	printf ("Converting movies not yet supported. Dumping instead...\n");
+	dumpRawResource(output);
 }
 
 void convertMIDIResource(MohawkOutputStream output) {
@@ -84,61 +105,78 @@
 	fclose(outputFile);
 }
 
-void outputMohawkStream(MohawkOutputStream output) {
-	// No specified name, prepare our own
-	if (output.name.empty()) {
-		char *strBuf = (char *)malloc(256);
-		sprintf(strBuf, "%s_%d", tag2str(output.tag), output.id);
-		output.name = strBuf;
-	}
+void outputMohawkStream(MohawkOutputStream output, bool do_conversion) {
+	// File output naming format preserves all archive information...
+	char *strBuf = (char *)malloc(256);
+	sprintf(strBuf, "%04d_%s_%d", output.index, tag2str(output.tag), output.id);
+	if(!output.name.empty())
+		sprintf(strBuf+strlen(strBuf), "_%s", output.name.c_str());
+	output.name = strBuf;
 
-	// Intercept the sound tags
-	if (output.tag == ID_TWAV || output.tag == ID_MSND || output.tag == ID_SND) {
-		convertSoundResource(output);
-		return;
-	}
+	if(do_conversion) {
+		// Intercept the sound tags
+		if (output.tag == ID_TWAV || output.tag == ID_MSND || output.tag == ID_SND) {
+			convertSoundResource(output);
+			return;
+		}
 
-	// Intercept the movie tag (need to change the offsets)
-	// TODO: Actually convert. Just dump for now.
-	if (output.tag == ID_TMOV) {
-		convertMovieResource(output);
-		//return;
-	}
+		// Intercept the movie tag (need to change the offsets)
+		if (output.tag == ID_TMOV) {
+			convertMovieResource(output);
+			return;
+		}
 
-	// Intercept the MIDI tag (strip out Mohawk header/Prg# stuff)
-	if (output.tag == ID_TMID) {
-		convertMIDIResource(output);
-		return;
+		// Intercept the MIDI tag (strip out Mohawk header/Prg# stuff)
+		if (output.tag == ID_TMID) {
+			convertMIDIResource(output);
+			return;
+		}
+
+		// TODO: Convert other resources? PICT/WDIB/tBMP?
 	}
 
-	// TODO: Convert other resources? PICT/WDIB/tBMP?
+	// Default to dump raw binary...
+	dumpRawResource(output);
+}
 
-	assert(outputBuffer);
+void printUsage(const char *appName) {
+	printf("Usage: %s [options] <mohawk archive> [tag id]\n", appName);
+	printf("Options : --raw     : Dump Resources as raw binary dump (default)");
+	printf("          --convert : Dump Resources as converted files");
+}
 
-	printf ("Extracting \'%s\'...\n", output.name.c_str());
+int main(int argc, char *argv[]) {
+	bool do_conversion = false;
+	int archive_arg;
 
-	FILE *outputFile = fopen(output.name.c_str(), "wb");
-	if (!outputFile) {
-		printf ("Could not open file for output!\n");
-		return;
-	}
+	// Parse parameters
+	for (archive_arg = 1; archive_arg < argc; archive_arg++) {
+		Common::String current = Common::String(argv[archive_arg]);
 
-	while (output.stream->pos() < output.stream->size()) {
-		uint32 size = output.stream->read(outputBuffer, MAX_BUF_SIZE);
-		fwrite(outputBuffer, 1, size, outputFile);
+		if(!current.hasPrefix("--"))
+			break;
+
+		// Decode options
+		if(current.equals("--raw"))
+			do_conversion = false;
+		else if(current.equals("--convert"))
+			do_conversion = true;
+		else {
+			printf("Unknown argument : \"%s\"\n", argv[archive_arg]);
+			printUsage(argv[0]);
+			return 1;
+		}
 	}
 
-	fflush(outputFile);
-	fclose(outputFile);
-}
+	printf("Debug : argc : %d archive_arg : %d\n", argc, archive_arg);
 
-int main(int argc, char *argv[]) {
-	if (argc < 2 || argc == 3) {
+	if(! (archive_arg == argc     - 1) || // No tag and id
+	     (archive_arg == argc - 2 - 1)) { //    tag and id
 		printUsage(argv[0]);
 		return 1;
 	}
 
-	FILE *file = fopen(argv[1], "rb");
+	FILE *file = fopen(argv[archive_arg], "rb");
 	if (!file) {
 		printf ("Could not open \'%s\'\n", argv[1]);
 		return 1;
@@ -155,14 +193,14 @@
 	// Allocate a buffer for the output
 	outputBuffer = (byte *)malloc(MAX_BUF_SIZE);
 
-	if (argc > 3) {
-		uint32 tag = READ_BE_UINT32(argv[2]);
-		uint16 id = (uint16)atoi(argv[3]);
+	if (argc == archive_arg - 2 - 1) {
+		uint32 tag = READ_BE_UINT32(argv[archive_arg+1]);
+		uint16 id = (uint16)atoi(argv[archive_arg+2]);
 
 		MohawkOutputStream output = mohawkFile->getRawData(tag, id);
 
 		if (output.stream) {
-			outputMohawkStream(output);
+			outputMohawkStream(output, do_conversion);
 			delete output.stream;
 		} else {
 			printf ("Could not find specified data!\n");
@@ -170,7 +208,7 @@
 	} else {
 		MohawkOutputStream output = mohawkFile->getNextFile();
 		while (output.stream) {
-			outputMohawkStream(output);
+			outputMohawkStream(output, do_conversion);
 			delete output.stream;
 			output = mohawkFile->getNextFile();
 		}

Modified: tools/trunk/engines/mohawk/mohawk_file.cpp
===================================================================
--- tools/trunk/engines/mohawk/mohawk_file.cpp	2010-01-18 23:07:56 UTC (rev 47364)
+++ tools/trunk/engines/mohawk/mohawk_file.cpp	2010-01-18 23:46:28 UTC (rev 47365)
@@ -189,7 +189,7 @@
 }
 
 MohawkOutputStream MohawkFile::getRawData(uint32 tag, uint16 id) {
-	MohawkOutputStream output = { 0, 0, 0, "" };
+	MohawkOutputStream output = { 0, 0, 0, 0, "" };
 
 	if (!_mhk)
 		return output;
@@ -220,6 +220,7 @@
 		output.stream = new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _fileTable[fileTableIndex].offset + _fileTable[fileTableIndex].dataSize);
 	output.tag = tag;
 	output.id = id;
+	output.index = fileTableIndex;
 	if (idIndex < _types[typeIndex].nameTable.num)
 		output.name = _types[typeIndex].nameTable.entries[idIndex].name;
 
@@ -227,7 +228,7 @@
 }
 
 MohawkOutputStream MohawkFile::getNextFile() {
-	MohawkOutputStream output = { 0, 0, 0, "" };
+	MohawkOutputStream output = { 0, 0, 0, 0, "" };
 
 	if (_curExType >= _typeTable.resource_types) // No more!
 		return output;
@@ -252,6 +253,7 @@
 	output.stream = new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _fileTable[fileTableIndex].offset + dataSize, false);
 	output.tag = _types[_curExType].tag;
 	output.id = _types[_curExType].resTable.entries[_curExTypeIndex].id;
+	output.index = fileTableIndex;
 
 	if (_curExTypeIndex < _types[_curExType].nameTable.num)
 		output.name = _types[_curExType].nameTable.entries[_curExTypeIndex].name;
@@ -347,7 +349,7 @@
 }
 
 MohawkOutputStream OldMohawkFile::getRawData(uint32 tag, uint16 id) {
-	MohawkOutputStream output = { 0, 0, 0, "" };
+	MohawkOutputStream output = { 0, 0, 0, 0, "" };
 
 	if (!_mhk)
 		return output;
@@ -365,12 +367,13 @@
 	output.stream = new Common::SeekableSubReadStream(_mhk, _types[typeIndex].resTable.entries[idIndex].offset, _types[typeIndex].resTable.entries[idIndex].offset + _types[typeIndex].resTable.entries[idIndex].size);
 	output.tag = tag;
 	output.id = id;
+	output.index = idIndex;
 
 	return output;
 }
 
 MohawkOutputStream OldMohawkFile::getNextFile() {
-	MohawkOutputStream output = { 0, 0, 0, "" };
+	MohawkOutputStream output = { 0, 0, 0, 0, "" };
 
 	if (_curExType >= _typeTable.resource_types) // No more!
 		return output;
@@ -386,6 +389,7 @@
 	output.stream = new Common::SeekableSubReadStream(_mhk, _types[_curExType].resTable.entries[_curExTypeIndex].offset, _types[_curExType].resTable.entries[_curExTypeIndex].offset + _types[_curExType].resTable.entries[_curExTypeIndex].size);
 	output.tag = _types[_curExType].tag;
 	output.id = _types[_curExType].resTable.entries[_curExTypeIndex].id;
+	output.index = _curExType;
 
 	_curExTypeIndex++;
 	return output;

Modified: tools/trunk/engines/mohawk/mohawk_file.h
===================================================================
--- tools/trunk/engines/mohawk/mohawk_file.h	2010-01-18 23:07:56 UTC (rev 47364)
+++ tools/trunk/engines/mohawk/mohawk_file.h	2010-01-18 23:46:28 UTC (rev 47365)
@@ -122,6 +122,7 @@
 	Common::SeekableSubReadStream *stream;
 	uint32 tag;
 	uint32 id;
+	uint32 index;
 	Common::String name;
 };
 


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