[Scummvm-cvs-logs] SF.net SVN: scummvm:[33439] residual/trunk

aquadran at users.sourceforge.net aquadran at users.sourceforge.net
Wed Jul 30 11:54:22 CEST 2008


Revision: 33439
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33439&view=rev
Author:   aquadran
Date:     2008-07-30 09:54:22 +0000 (Wed, 30 Jul 2008)

Log Message:
-----------
adopted debug to match scummvm version

Modified Paths:
--------------
    residual/trunk/common/debug.cpp
    residual/trunk/common/debug.h
    residual/trunk/common/file.cpp
    residual/trunk/common/util.h
    residual/trunk/engine/imuse/imuse_sndmgr.cpp

Modified: residual/trunk/common/debug.cpp
===================================================================
--- residual/trunk/common/debug.cpp	2008-07-30 08:23:04 UTC (rev 33438)
+++ residual/trunk/common/debug.cpp	2008-07-30 09:54:22 UTC (rev 33439)
@@ -25,22 +25,21 @@
 
 #include "common/sys.h"
 #include "common/debug.h"
+#include "common/str.h"
 
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
+#include "engine/backend/driver.h"
 
-const char *tag2str(uint32 tag) {
-	static char str[5];
+Common::String tag2string(uint32 tag) {
+	char str[5];
 	str[0] = (char)(tag >> 24);
 	str[1] = (char)(tag >> 16);
 	str[2] = (char)(tag >> 8);
 	str[3] = (char)tag;
 	str[4] = '\0';
-	return str;
+	return Common::String(str);
 }
 
-void hexdump(const byte * data, int len, int bytesPerLine) {
+void hexdump(const byte *data, int len, int bytesPerLine) {
 	assert(1 <= bytesPerLine && bytesPerLine <= 32);
 	int i;
 	byte c;
@@ -90,30 +89,126 @@
 	printf("|\n");
 }
 
-void CDECL warning(const char *fmt, ...) {
-	std::fprintf(stderr, "WARNING: ");
+static void debugHelper(const char *in_buf, bool caret = true) {
+	char buf[STRINGBUFLEN];
 
-	std::va_list va;
+	strcpy(buf, in_buf);
 
-	va_start(va, fmt);
-	std::vfprintf(stderr, fmt, va);
+	if (caret)
+		printf("%s\n", buf);
+	else
+		printf("%s", buf);
+
+#if defined(USE_WINDBG)
+	if (caret)
+		strcat(buf, "\n");
+#if defined(_WIN32_WCE)
+	TCHAR buf_unicode[1024];
+	MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
+	OutputDebugString(buf_unicode);
+#else
+	OutputDebugString(buf);
+#endif
+#endif
+
+	fflush(stdout);
+}
+
+void CDECL debug(const char *s, ...) {
+	char buf[STRINGBUFLEN];
+	va_list va;
+
+	va_start(va, s);
+	vsnprintf(buf, STRINGBUFLEN, s, va);
 	va_end(va);
-	std::fprintf(stderr, "\n");
+
+	debugHelper(buf);
 }
 
-void CDECL error(const char *fmt, ...) {
-	std::fprintf(stderr, "ERROR: ");
+void CDECL debug(int level, const char *s, ...) {
+	char buf[STRINGBUFLEN];
+	va_list va;
 
-	std::va_list va;
+	if (level > debugLevel)
+		return;
 
-	va_start(va, fmt);
-	std::vfprintf(stderr, fmt, va);
+	va_start(va, s);
+	vsnprintf(buf, STRINGBUFLEN, s, va);
 	va_end(va);
-	std::fprintf(stderr, "\n");
 
+	debugHelper(buf);
+}
+
+void NORETURN CDECL error(const char *s, ...) {
+	char buf_input[STRINGBUFLEN];
+	char buf_output[STRINGBUFLEN];
+	va_list va;
+
+	// Generate the full error message
+	va_start(va, s);
+	vsnprintf(buf_input, STRINGBUFLEN, s, va);
+	va_end(va);
+
+	strcpy(buf_output, buf_input);
+
+	// Print the error message to stderr
+	fprintf(stderr, "%s!\n", buf_output);
+
+#if defined(USE_WINDBG)
+#if defined(_WIN32_WCE)
+	TCHAR buf_output_unicode[1024];
+	MultiByteToWideChar(CP_ACP, 0, buf_output, strlen(buf_output) + 1, buf_output_unicode, sizeof(buf_output_unicode));
+	OutputDebugString(buf_output_unicode);
+#ifndef DEBUG
+	drawError(buf_output);
+#else
+	int cmon_break_into_the_debugger_if_you_please = *(int *)(buf_output + 1);	// bus error
+	printf("%d", cmon_break_into_the_debugger_if_you_please);			// don't optimize the int out
+#endif
+#else
+	OutputDebugString(buf_output);
+#endif
+#endif
+
+#ifdef PALMOS_MODE
+	extern void PalmFatalError(const char *err);
+	PalmFatalError(buf_output);
+#endif
+
+#ifdef __SYMBIAN32__
+	Symbian::FatalError(buf_output);
+#endif
+
+	if (g_driver)
+		g_driver->quit();
+
 	exit(1);
 }
 
+void CDECL warning(const char *fmt, ...) {
+	char buf[STRINGBUFLEN];
+	va_list va;
+
+	va_start(va, fmt);
+	vsnprintf(buf, STRINGBUFLEN, fmt, va);
+	va_end(va);
+
+#if !defined (__SYMBIAN32__)
+	fprintf(stderr, "WARNING: %s!\n", buf);
+#endif
+
+#if defined(USE_WINDBG)
+	strcat(buf, "\n");
+#if defined(_WIN32_WCE)
+	TCHAR buf_unicode[1024];
+	MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
+	OutputDebugString(buf_unicode);
+#else
+	OutputDebugString(buf);
+#endif
+#endif
+}
+
 const char *debug_levels[] = {
 	"NONE",
 	"NORMAL",

Modified: residual/trunk/common/debug.h
===================================================================
--- residual/trunk/common/debug.h	2008-07-30 08:23:04 UTC (rev 33438)
+++ residual/trunk/common/debug.h	2008-07-30 09:54:22 UTC (rev 33439)
@@ -25,6 +25,10 @@
 
 #include "common/sys.h"
 
+namespace Common {
+	class String;
+}
+
 #ifndef COMMON_DEBUG_H
 #define COMMON_DEBUG_H
 
@@ -51,8 +55,11 @@
 
 void warning(const char *fmt, ...);
 void error(const char *fmt, ...);
+void CDECL debug(int level, const char *s, ...);
+void CDECL debug(const char *s, ...);
 
-const char *tag2str(uint32 tag);
 void hexdump(const byte * data, int len, int bytesPerLine);
 
+Common::String tag2string(uint32 tag);
+
 #endif

Modified: residual/trunk/common/file.cpp
===================================================================
--- residual/trunk/common/file.cpp	2008-07-30 08:23:04 UTC (rev 33438)
+++ residual/trunk/common/file.cpp	2008-07-30 09:54:22 UTC (rev 33439)
@@ -306,13 +306,13 @@
 		_handle = fopenNoCase(filename, "", modeStr);
 	} else if (_filesMap && _filesMap->contains(fname)) {
 		fname = (*_filesMap)[fname];
-		//debug(3, "Opening hashed: %s", fname.c_str());
+		debug(3, "Opening hashed: %s", fname.c_str());
 		_handle = fopen(fname.c_str(), modeStr);
 	} else if (_filesMap && _filesMap->contains(fname + ".")) {
 		// WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
 		// sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
 		fname = (*_filesMap)[fname + "."];
-		//debug(3, "Opening hashed: %s", fname.c_str());
+		debug(3, "Opening hashed: %s", fname.c_str());
 		_handle = fopen(fname.c_str(), modeStr);
 	} else {
 
@@ -347,10 +347,10 @@
 	}
 
 	if (_handle == NULL) {
-/*		if (mode == kFileReadMode)
+		if (mode == kFileReadMode)
 			debug(2, "File %s not found", filename.c_str());
 		else
-			debug(2, "File %s not opened", filename.c_str());*/
+			debug(2, "File %s not opened", filename.c_str());
 		return false;
 	}
 
@@ -395,10 +395,10 @@
 	_handle = fopen(node.getPath().c_str(), modeStr);
 
 	if (_handle == NULL) {
-/*		if (mode == kFileReadMode)
+		if (mode == kFileReadMode)
 			debug(2, "File %s not found", filename.c_str());
 		else
-			debug(2, "File %s not opened", filename.c_str());*/
+			debug(2, "File %s not opened", filename.c_str());
 		return false;
 	}
 

Modified: residual/trunk/common/util.h
===================================================================
--- residual/trunk/common/util.h	2008-07-30 08:23:04 UTC (rev 33438)
+++ residual/trunk/common/util.h	2008-07-30 09:54:22 UTC (rev 33439)
@@ -26,6 +26,7 @@
 #define COMMON_UTIL_H
 
 #include "common/sys.h"
+#include "common/debug.h"
 
 #ifdef MIN
 #undef MIN
@@ -35,9 +36,9 @@
 #undef MAX
 #endif
 
-template<typename T> inline T ABS (T x)		{ return (x>=0) ? x : -x; }
-template<typename T> inline T MIN (T a, T b)	{ return (a<b) ? a : b; }
-template<typename T> inline T MAX (T a, T b)	{ return (a>b) ? a : b; }
+template<typename T> inline T ABS (T x)			{ return (x >= 0) ? x : -x; }
+template<typename T> inline T MIN (T a, T b)	{ return (a < b) ? a : b; }
+template<typename T> inline T MAX (T a, T b)	{ return (a > b) ? a : b; }
 template<typename T> inline T CLIP (T v, T amin, T amax)
 		{ if (v < amin) return amin; else if (v > amax) return amax; else return v; }
 

Modified: residual/trunk/engine/imuse/imuse_sndmgr.cpp
===================================================================
--- residual/trunk/engine/imuse/imuse_sndmgr.cpp	2008-07-30 08:23:04 UTC (rev 33438)
+++ residual/trunk/engine/imuse/imuse_sndmgr.cpp	2008-07-30 09:54:22 UTC (rev 33439)
@@ -25,8 +25,9 @@
 
 #include "common/sys.h"
 #include "common/endian.h"
-#include "common/debug.h"
+#include "common/util.h"
 #include "common/timer.h"
+#include "common/str.h"
 
 #include "engine/resource.h"
 
@@ -70,7 +71,7 @@
 			size = READ_BE_UINT32(ptr); ptr += size + 4;
 			break;
 		default:
-			error("ImuseSndMgr::countElements() Unknown MAP tag '%s'", tag2str(tag));
+			error("ImuseSndMgr::countElements() Unknown MAP tag '%s'", tag2string(tag).c_str());
 		}
 	} while (tag != MKID_BE('DATA'));
 }
@@ -133,7 +134,7 @@
 				ptr += 4;
 				break;
 			default:
-				error("ImuseSndMgr::prepareSound(%s) Unknown MAP tag '%s'", sound->name, tag2str(tag));
+				error("ImuseSndMgr::prepareSound(%s) Unknown MAP tag '%s'", sound->name, tag2string(tag).c_str());
 			}
 		} while (tag != MKID_BE('DATA'));
 		headerSize = ptr - s_ptr;


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