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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Dec 17 16:37:44 CET 2010


Revision: 54946
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54946&view=rev
Author:   fingolfin
Date:     2010-12-17 15:37:43 +0000 (Fri, 17 Dec 2010)

Log Message:
-----------
TOOLS: better string output for descumm (patch #3049421)

Modified Paths:
--------------
    tools/trunk/engines/scumm/descumm-common.cpp
    tools/trunk/engines/scumm/descumm.cpp
    tools/trunk/engines/scumm/descumm.h
    tools/trunk/engines/scumm/descumm6.cpp

Modified: tools/trunk/engines/scumm/descumm-common.cpp
===================================================================
--- tools/trunk/engines/scumm/descumm-common.cpp	2010-12-17 14:36:32 UTC (rev 54945)
+++ tools/trunk/engines/scumm/descumm-common.cpp	2010-12-17 15:37:43 UTC (rev 54946)
@@ -242,3 +242,127 @@
 		pendingElse = false;
 	}
 }
+
+char *put_ascii(char *buf, int i) {
+	if (i > 31 && i < 128) {
+		// non-printable chars are escaped by backslashes as so: "\x00"
+		// backslashes and quote marks are escaped like so: "\\" "\""
+		if (i == '\\' || i == '"') {
+			buf[0] = '\\';
+			buf++;
+		}
+		buf[0] = i;
+		buf[1] = 0;
+		return buf + 1;
+	}
+	return buf + sprintf(buf, "\\x%.2X", i);
+}
+
+extern char *get_var(char *buf);
+extern char *get_var6(char *buf);
+
+char *get_string(char *buf) {
+	byte cmd;
+	char *e = buf;
+	bool in = false;
+	bool in_function = false;
+	int i;
+
+	while ((cmd = get_byte()) != 0) {
+		if (cmd == 0xFF || cmd == 0xFE) {
+			if (in) {
+				e += sprintf(e, "\" + ");
+				in = false;
+			}
+			in_function = true;
+			i = get_byte();
+			switch (i) {
+			case 1: // newline
+				e += sprintf(e, "newline()");
+				break;
+			case 2:
+				e += sprintf(e, "keepText()");
+				break;
+			case 3:
+				e += sprintf(e, "wait()");
+				break;
+			case 4:		// addIntToStack
+				e += sprintf(e, "getInt(");
+				goto addVarToStack;
+			case 5:		// addVerbToStack
+				e += sprintf(e, "getVerb(");
+				goto addVarToStack;
+			case 6:		// addNameToStack
+				e += sprintf(e, "getName(");
+				goto addVarToStack;
+			case 7:		// addStringToStack
+				e += sprintf(e, "getString(");
+			addVarToStack:
+				if (g_options.scriptVersion >= 6)  {
+					e = get_var6(e);
+				} else {
+					e = get_var(e);
+				}
+				e += sprintf(e, ")");
+				break;
+			case 9:
+				e += sprintf(e, "startAnim(%d)", get_word());
+				break;
+			case 10:
+				e += sprintf(e, "sound(");
+				// positions 2, 3, 6, 7 are the offset in MONSTER.SOU (LE).
+				// positions 10, 11, 14, 15 are the VCTL block size (LE).
+				{
+					// show the voice's position in the MONSTER.SOU
+				    int p = 0;
+				    p += get_word();
+				    g_scriptCurPos += 2; // skip the next "0xFF 0x0A"
+				    p += get_word() << 2;
+				    e += sprintf(e, "0x%X, ", p);
+
+				    g_scriptCurPos += 2; // skip the next "0xFF 0x0A"
+
+				    // show the size of the VCTL chunk/lip-synch tags
+				    p = 0;
+				    p += get_word();
+				    g_scriptCurPos += 2; // skip the next "0xFF 0x0A"
+				    p += get_word() << 2;
+				    e += sprintf(e, "0x%X)", p);
+				}
+				break;
+			case 12:
+				e += sprintf(e, "setColor(%d)", get_word());
+				break;
+			case 13: // was unk2
+				e += sprintf(e, "unknown13(%d)", get_word());
+				break;
+			case 14:
+				e += sprintf(e, "setFont(%d)", get_word());
+				break;
+			case 32: // Workaround for a script bug in Indy3
+			case 46: // Workaround for a script bug in Indy3
+				if (g_options.scriptVersion == 3 && g_options.IndyFlag) {
+					buf += sprintf(buf, "\\x%.2X", 0xE1); // should output German "sz" in-game.
+					continue;
+				}
+				// fall-through
+			default:
+				e += sprintf(e, "unknown%d(%d)", i, get_word());
+			}
+		} else {
+			if (in_function) {
+				e += sprintf(e, " + ");
+				in_function = false;
+			}
+			if (!in) {
+				*e++ = '"';
+				in = true;
+			}
+			e = put_ascii(e, cmd);
+		}
+	}
+	if (in)
+		*e++ = '"';
+	*e = 0;
+	return e;
+}

Modified: tools/trunk/engines/scumm/descumm.cpp
===================================================================
--- tools/trunk/engines/scumm/descumm.cpp	2010-12-17 14:36:32 UTC (rev 54945)
+++ tools/trunk/engines/scumm/descumm.cpp	2010-12-17 15:37:43 UTC (rev 54946)
@@ -568,51 +568,7 @@
 	return strecpy(buf, "]");
 }
 
-char *putascii(char *buf, int i) {
-	if (i > 31 && i < 128) {
-		// non-printable chars are escaped by backslashes as so: "\x00"
-		// backslashes and quote marks are escaped like so: "\\" "\""
-		if (i == '\\' || i == '"') {
-			buf[0] = '\\';
-			buf++;
-		}
-		buf[0] = i;
-		buf[1] = 0;
-		return buf + 1;
-	}
-	return buf + sprintf(buf, "\\x%.2X", i);
-}
 
-char *get_ascii(char *buf) {
-	int i;
-
-	buf = strecpy(buf, "\"");
-
-	do {
-		i = get_byte();
-		if (!i)
-			break;
-		buf = putascii(buf, i);
-		if (i == 255) {
-			i = get_byte();
-			buf = putascii(buf, i);
-
-			// Workaround for a script bug in Indy3
-			if (i == 46 && g_options.scriptVersion == 3 && g_options.IndyFlag)
-				continue;
-
-			if (i != 1 && i != 2 && i != 3 && i != 8) {
-				buf = putascii(buf, get_byte());
-				buf = putascii(buf, get_byte());
-			}
-		}
-	} while (1);
-
-	return strecpy(buf, "\"");
-}
-
-
-
 char *add_a_tok(char *buf, int type) {
 	switch (type) {
 	case TOK_BYTE:
@@ -628,11 +584,11 @@
 		buf = get_list(buf);
 		break;
 	case TOK_ASCII:
-		buf = get_ascii(buf);
+		buf = get_string(buf);
 		break;
 	case TOK_CHAR:
 		error("this code seems to be dead");
-		buf = putascii(buf, get_byte());
+		buf = put_ascii(buf, get_byte());
 		break;
 	}
 	return buf;
@@ -955,7 +911,7 @@
 	buf = strchr(strcpy(buf, "PutCodeInString("), 0);
 	buf = get_var_or_byte(buf, opcode & 0x80);
 	buf = strchr(strcpy(buf, ", "), 0);
-	buf = get_ascii(buf);
+	buf = get_string(buf);
 	strcpy(buf, ");");
 }
 
@@ -1477,7 +1433,7 @@
 			break;
 		case 0xF:{
 				buf = strecpy(buf, "Text(");
-				buf = get_ascii(buf);
+				buf = get_string(buf);
 				buf = strecpy(buf, ")");
 			}
 			goto exit_proc;
@@ -3674,7 +3630,7 @@
 					break;
 				case 0x03:
 					buf += sprintf(buf, ", Open(");
-					buf = get_ascii(buf);
+					buf = get_string(buf);
 					buf += sprintf(buf, ")");
 					break;
 				case 0x04:

Modified: tools/trunk/engines/scumm/descumm.h
===================================================================
--- tools/trunk/engines/scumm/descumm.h	2010-12-17 14:36:32 UTC (rev 54945)
+++ tools/trunk/engines/scumm/descumm.h	2010-12-17 15:37:43 UTC (rev 54946)
@@ -160,6 +160,9 @@
 
 extern void outputLine(const char *buf, int curoffs, int opcode, int indent);
 
+extern char *put_ascii(char *buf, int i);
+extern char *get_string(char *buf);
+
 extern char *strecpy(char *buf, const char *src);
 extern int get_curoffs();
 extern int get_byte();

Modified: tools/trunk/engines/scumm/descumm6.cpp
===================================================================
--- tools/trunk/engines/scumm/descumm6.cpp	2010-12-17 14:36:32 UTC (rev 54945)
+++ tools/trunk/engines/scumm/descumm6.cpp	2010-12-17 15:37:43 UTC (rev 54946)
@@ -1063,6 +1063,11 @@
 	return new ListStackEnt(pop());
 }
 
+char *get_var6(char *buf) {
+	VarStackEnt tmp(get_word());
+	return tmp.asText(buf);
+}
+
 void invalidop(const char *cmd, int op) {
 	if (cmd)
 		error("Unknown opcode %s:0x%x (stack count %d)", cmd, op, num_stack);
@@ -1159,71 +1164,10 @@
 	delete se;
 }
 
+
 StackEnt *se_get_string() {
-	byte cmd;
 	char buf[1024];
-	char *e = buf;
-	bool in = false;
-	int i;
-
-	while ((cmd = get_byte()) != 0) {
-		if (cmd == 0xFF || cmd == 0xFE) {
-			if (in) {
-				*e++ = '"';
-				in = false;
-			}
-			i = get_byte();
-			switch (i) {
-			case 1:
-				e += sprintf(e, ":newline:");
-				break;
-			case 2:
-				e += sprintf(e, ":keeptext:");
-				break;
-			case 3:
-				e += sprintf(e, ":wait:");
-				break;
-			case 4:		// addIntToStack
-			case 5:		// addVerbToStack
-			case 6:		// addNameToStack
-			case 7:		// addStringToStack
-				{
-				VarStackEnt tmp(get_word());
-				e += sprintf(e, ":");
-				e = tmp.asText(e);
-				e += sprintf(e, ":");
-				}
-				break;
-			case 9:
-				e += sprintf(e, ":startanim=%d:", get_word());
-				break;
-			case 10:
-				e += sprintf(e, ":sound:");
-				g_scriptCurPos += 14;
-				break;
-			case 14:
-				e += sprintf(e, ":setfont=%d:", get_word());
-				break;
-			case 12:
-				e += sprintf(e, ":setcolor=%d:", get_word());
-				break;
-			case 13:
-				e += sprintf(e, ":unk2=%d:", get_word());
-				break;
-			default:
-				e += sprintf(e, ":unk%d=%d:", i, get_word());
-			}
-		} else {
-			if (!in) {
-				*e++ = '"';
-				in = true;
-			}
-			*e++ = cmd;
-		}
-	}
-	if (in)
-		*e++ = '"';
-	*e = 0;
+	get_string(buf); // ignore returned value
 	return se_complex(buf);
 }
 


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