[Scummvm-cvs-logs] SF.net SVN: scummvm: [24936] tools/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Dec 27 17:27:26 CET 2006


Revision: 24936
          http://scummvm.svn.sourceforge.net/scummvm/?rev=24936&view=rev
Author:   fingolfin
Date:     2006-12-27 08:27:25 -0800 (Wed, 27 Dec 2006)

Log Message:
-----------
more cleanup

Modified Paths:
--------------
    tools/trunk/descumm-common.cpp
    tools/trunk/descumm-tool.cpp
    tools/trunk/descumm.h

Modified: tools/trunk/descumm-common.cpp
===================================================================
--- tools/trunk/descumm-common.cpp	2006-12-27 14:10:18 UTC (rev 24935)
+++ tools/trunk/descumm-common.cpp	2006-12-27 16:27:25 UTC (rev 24936)
@@ -37,7 +37,7 @@
 Options g_options;
 
 byte *g_scriptCurPos, *g_scriptStart;
-int offs_of_line;
+int currentOpcodeBlockStart;
 
 uint g_scriptSize;
 
@@ -140,7 +140,7 @@
 		i = (int16)READ_LE_UINT16(g_scriptStart+to-2);
 	}
 	
-	p.isWhile = p.isWhile && (offs_of_line == (int)to + i);
+	p.isWhile = p.isWhile && (currentOpcodeBlockStart == (int)to + i);
 	p.from = cur;
 	p.to = to;
 	
@@ -239,8 +239,8 @@
 	if (pendingElse) {
 		char buf[32];
 		sprintf(buf, g_options.alwaysShowOffs ? "} else /*%.4X*/ {" : "} else {", pendingElseTo);
-		outputLine(buf, offs_of_line, pendingElseOpcode, pendingElseIndent - 1);
-		offs_of_line = pendingElseOffs;
+		outputLine(buf, currentOpcodeBlockStart, pendingElseOpcode, pendingElseIndent - 1);
+		currentOpcodeBlockStart = pendingElseOffs;
 		pendingElse = false;
 	}
 }

Modified: tools/trunk/descumm-tool.cpp
===================================================================
--- tools/trunk/descumm-tool.cpp	2006-12-27 14:10:18 UTC (rev 24935)
+++ tools/trunk/descumm-tool.cpp	2006-12-27 16:27:25 UTC (rev 24936)
@@ -251,34 +251,7 @@
 	return filename;
 }
 
-int main(int argc, char *argv[]) {
-	FILE *in;
-	byte *memorg;
-	char *filename;
-
-	memset(&g_options, 0, sizeof(g_options));
-	g_options.scriptVersion = 0xff;
-	
-	// Parse the arguments
-	filename = parseCommandLine(argc, argv);
-	if (!filename || g_options.scriptVersion == 0xff)
-		ShowHelpAndExit();
-
-	in = fopen(filename, "rb");
-	if (!in) {
-		printf("Unable to open %s\n", filename);
-		return 1;
-	}
-
-	// Read the file into memory
-	memorg = (byte *)malloc(MAX_FILE_SIZE);
-	g_scriptSize = fread(memorg, 1, MAX_FILE_SIZE, in);
-	fclose(in);
-
-	offs_of_line = 0;
-	g_scriptStart = memorg;
-	g_scriptCurPos = g_scriptStart;
-
+void parseHeader() {
 	if (g_options.GF_UNBLOCKED) {
 		if (g_scriptSize < 4) {
 			error("File too small to be a script");
@@ -286,9 +259,9 @@
 		// Hack to detect verb script: first 4 bytes should be file length
 		if (READ_LE_UINT32(g_scriptStart) == g_scriptSize) {
 			if (g_options.scriptVersion <= 2)
-				offs_of_line = skipVerbHeader_V12(g_scriptStart);
+				currentOpcodeBlockStart = skipVerbHeader_V12(g_scriptStart);
 			else
-				offs_of_line = skipVerbHeader_V34(g_scriptStart);
+				currentOpcodeBlockStart = skipVerbHeader_V34(g_scriptStart);
 		} else {
 			g_scriptStart += 4;
 		}
@@ -338,9 +311,9 @@
 		case 'VERB':
 			if (g_options.scriptVersion == 8) {
 				g_scriptStart += 8;
-				offs_of_line = skipVerbHeader_V8(g_scriptStart);
+				currentOpcodeBlockStart = skipVerbHeader_V8(g_scriptStart);
 			} else
-				offs_of_line = skipVerbHeader_V567(g_scriptStart);
+				currentOpcodeBlockStart = skipVerbHeader_V567(g_scriptStart);
 			break;											/* Verb */
 		default:
 			error("Unknown script type");
@@ -364,17 +337,47 @@
 			g_scriptStart += 6;
 			break;			/* Exit code */
 		case 'OC':
-			offs_of_line = skipVerbHeader_V34(g_scriptStart);
+			currentOpcodeBlockStart = skipVerbHeader_V34(g_scriptStart);
 			break;			/* Verb */
 		default:
 			error("Unknown script type");
 		}
 	}
+}
 
-	g_scriptCurPos = g_scriptStart + offs_of_line;
+int main(int argc, char *argv[]) {
+	FILE *in;
+	byte *fileBuffer;
+	char *filename;
 
-	offs_of_line = get_curoffs();
-	while (g_scriptCurPos < g_scriptSize + memorg) {
+	memset(&g_options, 0, sizeof(g_options));
+	g_options.scriptVersion = 0xff;
+	
+	// Parse the arguments
+	filename = parseCommandLine(argc, argv);
+	if (!filename || g_options.scriptVersion == 0xff)
+		ShowHelpAndExit();
+
+	in = fopen(filename, "rb");
+	if (!in) {
+		printf("Unable to open %s\n", filename);
+		return 1;
+	}
+
+	// Read the file into memory
+	fileBuffer = (byte *)malloc(MAX_FILE_SIZE);
+	g_scriptSize = fread(fileBuffer, 1, MAX_FILE_SIZE, in);
+	fclose(in);
+
+	g_scriptStart = fileBuffer;
+	g_scriptCurPos = g_scriptStart;
+	currentOpcodeBlockStart = 0;
+
+	// Read (and skip over) the file header
+	parseHeader();
+	g_scriptCurPos = g_scriptStart + currentOpcodeBlockStart;
+
+	while (g_scriptCurPos < g_scriptSize + fileBuffer) {
 		byte opcode = *g_scriptCurPos;
 		int j = g_blockStack.size();
 		char outputLineBuffer[8192] = "";
@@ -411,13 +414,13 @@
 				haveElse = false;
 				j--;
 			}
-			outputLine(outputLineBuffer, offs_of_line, opcode, j);
-			offs_of_line = get_curoffs();
+			outputLine(outputLineBuffer, currentOpcodeBlockStart, opcode, j);
+			currentOpcodeBlockStart = get_curoffs();
 		}
 		while (!g_blockStack.empty() && get_curoffs() >= (int)g_blockStack.top().to) {
 			g_blockStack.pop();
-			outputLine("}", offs_of_line, -1, g_blockStack.size());
-			offs_of_line = get_curoffs();
+			outputLine("}", currentOpcodeBlockStart, -1, g_blockStack.size());
+			currentOpcodeBlockStart = get_curoffs();
 		}
 		fflush(stdout);
 	}
@@ -437,7 +440,7 @@
 		}
 	}
 */
-	free(memorg);
+	free(fileBuffer);
 
 	return 0;
 }

Modified: tools/trunk/descumm.h
===================================================================
--- tools/trunk/descumm.h	2006-12-27 14:10:18 UTC (rev 24935)
+++ tools/trunk/descumm.h	2006-12-27 16:27:25 UTC (rev 24936)
@@ -147,12 +147,12 @@
 extern byte *g_scriptCurPos;
 
 
-// The variable offs_of_line indicates the offset associated to
+// The variable currentOpcodeBlockStart indicates the offset associated to
 // the next line to be printed; in other words, it is the offset of
 // the first bytecode op which is part of the current line (recall
 // that a single line can correspond to multiple ops, e.g. several
 // push-ops plus one op using all those pushed values).
-extern int offs_of_line;
+extern int currentOpcodeBlockStart;
 
 //
 // Common


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